Is there a Logback Layout that Creates JSON Objects with Message Parameters as Attributes?

后端 未结 5 744
天命终不由人
天命终不由人 2021-02-02 09:32

I want to send log events to Loggly as JSON objects with parameterized string messages. Our project currently has a lot of code that looks like this:

String some         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 09:41

    Like already answered you'll get a one-dimensional JSON tree with MDC and/or using a Marker with logstash-logback-encoder.

    If you are also looking for the following:

    • codebooks for definition of logged datatype key and type,
    • configuration of log-aggregation tools (like elasticsearch)
    • generated Java helper-code for efficient and correct logging

    then try a project I've created: json-log-domain. It defines a simple YAML-format definition from which the above can be generated.

    An example helper-code statement would be

    logger.info(host("localhost").port(8080), "Hello world");
    

    while generated markdown would like something like this.

提交回复
热议问题