Giter Site home page Giter Site logo

Comments (6)

cyberluke avatar cyberluke commented on August 19, 2024

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.

vy avatar vy commented on August 19, 2024

@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.

cyberluke avatar cyberluke commented on August 19, 2024

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.

vy avatar vy commented on August 19, 2024

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.

cyberluke avatar cyberluke commented on August 19, 2024

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.

vy avatar vy commented on August 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.