# How to use log4jplus with logstash?

**URL:** <https://discuss.elastic.co/t/how-to-use-log4jplus-with-logstash/118869>\
**Category:** Logstash\
**Created:** [February 7, 2018, 3:29pm UTC](https://discuss.elastic.co/t/how-to-use-log4jplus-with-logstash/118869 "2018-02-07T15:29:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![durgeshtanuku](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/durgeshtanuku/32/27480_2.png) [@durgeshtanuku](https://discuss.elastic.co/u/durgeshtanuku)\
**Post date:** [February 7, 2018, 3:29pm UTC](https://discuss.elastic.co/t/how-to-use-log4jplus-with-logstash/118869/1 "2018-02-07T15:29:39Z")

</div>

I'm new to logstash.  
I'm trying to send logs of my C++ application to logstash using log4cplus library. I need to send some json data from my application to logstash. To start with I have written some piece of code that sends a string to logstash.

Below is my logstash configurations

input {  
tcp {  
port =\> 5044  
}  
}

filter{  
}

output {  
stdout {  
codec =\> rubydebug  
}  
}

Below is my code that sends data to logstash and log4cplus configurations.

**code :**

PropertyConfigurator config(configFile);  
config.configure();  
std::string msg = "test msg";  
Logger root = Logger::getRoot();  
LOG4CPLUS\_INFO(root,msg);

**log4cplus conf :**

log4cplus.rootLogger=INFO, SA  
log4cplus.appender.SA=log4cplus::SocketAppender  
log4cplus.appender.SA.port=5044  
log4cplus.appender.SA.host=127.0.0.1  
log4cplus.appender.SA.serverName=MyServer  
log4cplus.appender.SA.layout=log4cplus::PatternLayout  
log4cplus.appender.SA.layout.ConversionPattern=%m%n

I was expecting "test message" to be printed on logstash console. But i was receiving some garbage data as shown below.

{  
"@version" =\> "1",  
"host" =\> "localhost",  
"message" =\> "\u0000\u0000\u0000q\u0003\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0004root\u0000\u0000N \u0000\u0000\u0000\u0000\u0000\u0000\u0000\btest msg\u0000\u0000\u0000\u000F140382836238144Z{\u0014N\u0000\u0004\u0003\xC0\u0000\u0000\u0000\u0013../src/property.cpp\u0000\u0000\u00002\u0000\u0000\u0000\u0015int main(int, char\*\*)",  
"@timestamp" =\> 2018-02-07T14:59:26.284Z,  
"port" =\> 47148  
}

Can i do something in logstash configurations to get actual message ?  
Also is it possible to use log4cplus with logstash for logging ?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 8, 2018, 8:24pm UTC](https://discuss.elastic.co/t/how-to-use-log4jplus-with-logstash/118869/2 "2018-02-08T20:24:14Z")

</div>

Log4cplus's SocketAppender apparently serializes the log records in a binary format. Logstash can't interpret it out of the box, but it wouldn't be too hard to write a custom codec for it.

I'm not a fan of log frameworks talking directly to Logstash. How does Log4cplus behave if it can't reach Logstash?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 8, 2018, 8:24pm UTC](https://discuss.elastic.co/t/how-to-use-log4jplus-with-logstash/118869/3 "2018-03-08T20:24:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
