Comments (6)
Does prettyPrint work for you? It adds a new line, which causes Logstash to throw exception about parse error. How do you configure it?
from log4j2-logstash-layout.
@cyberluke, what does your layout+appender configuration look like? You need to provide a little bit more information so I can reproduce the issue. And yes, prettyPrintEnabled="true"
works for me, though I am using log4j2-redis-appender.
from log4j2-logstash-layout.
I'm using standard file appender and logstash scans the log file as input (as seen in the first post). I tried also socket appender. Yeah, so I guess redis appender will do something different, so it can recognize individual lines correctly.
from log4j2-logstash-layout.
Using the following setup
$ cat /tmp/logstash.conf
input {
file {
codec => json
type => "log4j-json"
path => "/tmp/log4j2.log"
}
}
output {
stdout {}
}
$ echo -n > /tmp/log4j2.log
I have downloaded logstash-6.0.0
and run it as follows:
$ logstash-6.0.0/bin/logstash -f /tmp/logstash.conf
Then I ran com.vlkan.log4j2.logstash.layout.demo.LogstashLayoutDemo
(shipped with log4j2-logstash-layout
sources) from my IDE where I configure layout-demo/src/main/resources/log4j2.xml
as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<File name="FILE" fileName="/tmp/log4j2.log">
<LogstashLayout dateTimeFormatPattern="yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"
prettyPrintEnabled="false"
locationInfoEnabled="true"
templateUri="classpath:LogstashJsonEventLayoutV1.json"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="FILE"/>
</Root>
</Loggers>
</Configuration>
I was able to see Logstash swiftly displaying the polled log entries to console. Further, the log file content was JSON-per-line as expected:
$ cat /tmp/log4j2.log
{"line_number":10,"class":"com.vlkan.log4j2.logstash.layout.demo.LogstashLayoutDemo","@version":1,"source_host":"varlik","message":"Hello, world!","thread_name":"main","@timestamp":"2017-12-04T19:49:10.207+01:00","level":"INFO","file":"LogstashLayoutDemo.java","method":"main","logger_name":"com.vlkan.log4j2.logstash.layout.demo.LogstashLayoutDemo"}
{"exception":{"exception_class":"java.lang.RuntimeException","exception_message":"test"},"line_number":12,"class":"com.vlkan.log4j2.logstash.layout.demo.LogstashLayoutDemo","@version":1,"source_host":"varlik","message":"Hello, error!","thread_name":"main","@timestamp":"2017-12-04T19:49:10.227+01:00","level":"ERROR","file":"LogstashLayoutDemo.java","method":"main","logger_name":"com.vlkan.log4j2.logstash.layout.demo.LogstashLayoutDemo"}
I am not a Logstash expert, but just happen to know Java to write my own JSON layout addressing certain shortcomings of other Log4j2 JSON layout plugins. If you can provide me a reproducible case (like I did above), I can help you with investigating the issue.
from log4j2-logstash-layout.
With prettyPrintEnabled="false" it worked before. I was just questioning how is it working for you with prettyPrintEnabled="true", because you mention this in your github readme :))
from log4j2-logstash-layout.
Ah! Now I see your point. In the README, I do not mentioned any particular appender, AFAIK. The selling point of the layout plugin is the vast potential for customization. Though I cannot comment on whether all of these features will work with a particular appender or not. Maybe I should mention about this in a FAQ. Thanks for the tip.
from log4j2-logstash-layout.
Related Issues (20)
- BufferOverflowException get thrown for messages of a larger size HOT 7
- LogstashLayout with log4j2-elasticsearch appender HOT 1
- Introduce properties to globally set LogstashLayout.Builder defaults
- Nullpointer exceptions at LogstashLayoutSerializationContexts$StringTruncatingGeneratorDelegate HOT 1
- Any template ready for GCP? HOT 9
- Message lost if exceeding maxStringLength and emptyPropertyExclusionEnabled is true HOT 4
- Use ByteArrayOutputStream instead of ByteBufferOutputStream to avoid message loss HOT 8
- Stacktraces larger than maxStringLength are not truncated HOT 7
- Failed serializing JSON: BufferOverflowException HOT 10
- How to output ThreadContext (ex -MDC fields) HOT 1
- Review request for Log4j JsonTemplateLayout HOT 7
- How exactly is MapMessage supposed to be handled? HOT 7
- Multiple template variables in single property lead to an exception HOT 2
- Fallback for json:map: fields for libraries HOT 1
- NoClassDefFoundError: logstash.layout.resolver.TemplateResolvers (initialization failure) HOT 1
- Remove max byte count cap? HOT 1
- Reference whole MapMessage - and not just keys HOT 13
- Compiling with JDK 8 results in java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer; HOT 4
- Marker lookup subsitutes literal string when marker not available HOT 1
- BufferOverflowException occurs intermittently when sending data via socket appender HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log4j2-logstash-layout.