LOGBACK : How to log entire msg using JSONLayout

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 18:53:24

问题


We are changing our logs from Text to JSON. I used below code to implement JSON logs :

    LayoutWrappingEncoder layoutEncoder = new LayoutWrappingEncoder();
    ch.qos.logback.contrib.json.classic.JsonLayout layout= new ch.qos.logback.contrib.json.classic.JsonLayout();

    ch.qos.logback.contrib.jackson.JacksonJsonFormatter jsonFormatter=new ch.qos.logback.contrib.jackson.JacksonJsonFormatter();
    jsonFormatter.setPrettyPrint(true);

    layout.setJsonFormatter(jsonFormatter);
    layout.setTimestampFormat("yyyy-MM-dd' 'HH:mm:ss.SSS");
    layoutEncoder.setLayout(layout);

But I see that JSON logs are not printed entirely.

{
    "timestamp" : "2019-08-22 10:12:15.790", 
    "level" : "ERROR",
    "thread" : "qtp1346354118-22",  
    "logger" :"com.SomeClass",
    "message" : "Exception  from : com.class.method() \n",
    "context" : "default",
    "exception" : "java.lang.NullPointerException: null\r\n"
}

Now, the exception are not printed with complete stack trace, like how they use to get logs in text logs. Also I could see new line escape sequence getting printed which also does not happen in text logs.

I tried exploring some properties in JSONLayout but none of them solved my problem.

So what else can I try here.

来源:https://stackoverflow.com/questions/57602337/logback-how-to-log-entire-msg-using-jsonlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!