Search code examples
jsonlogginglog4j

Logging in json


I would like to log messages in a jSon format from within Java. I would like the convenience of professional logging like log4j for hierarchical loggers and method names, but I would also like to output other key-value names in the json object.

I am looking for output simillar to this:

{ 'time':'123' , level:'debug', action: 'open',filename:'bla.txt'}

{ 'time':'432' , level:'info', action: 'calculate',result:'353'}

If I use log4j and reformat I cannot get the automatic values (timestamp for example) in the same object as the logged values.

Is there a logging framework or plugin to solve this?


Solution

  • I started using this project Works great

    https://github.com/michaeltandy/log4j-json