Extension to Tomcat logging that will format the contents as JSON to be better compatible with logging environments for microservices.
If everything is configured correctly you will see output like this on our console:
..
{"when":"2018-11-07T14:40:58.540+0100","level":"INFO","source":"org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:488)","logger":"org.apache.coyote.http11.Http11AprProtocol","thread":"main","processId":22640,"message":"Starting ProtocolHandler [\"http-apr-8080\"]"}
{"when":"2018-11-07T14:40:58.555+0100","level":"INFO","source":"org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:488)","logger":"org.apache.coyote.ajp.AjpAprProtocol","thread":"main","processId":22640,"message":"Starting ProtocolHandler [\"ajp-apr-8009\"]"}
{"when":"2018-11-07T14:40:58.560+0100","level":"INFO","source":"org.apache.catalina.startup.Catalina.start(Catalina.java:654)","logger":"org.apache.catalina.startup.Catalina","thread":"main","processId":22640,"message":"Server startup in 859 ms"}
..
Go to Release page and download the matching version of tomcat-juli.jar
for your Tomcat version. If you have Tomcat 8.5.32
running download tomcat-juli-8.5.32.jar
and so on...
Replace bin/tomcat-juli.jar
inside your Tomcat distribution directory with this file.
No worries! This files is a combined version of the original Tomcat version and the new functionality.
Just replace the content of conf/logging.properties
in your Tomcat distribution directory with the following content:
handlers = org.echocat.tjl.Handler
This will log everything directly to the console in JSON format (by default).
You can either specify a system property or environment variable to change the behavior of the logging of the Tomcat. This values always override every settings in conf/logging.properties
.
System property | Environment property | Description |
---|---|---|
log.format |
LOG_FORMAT |
Forces a different formatter. See Available formats. |
log.level |
LOG_LEVEL |
Forces a different global log level. Pleas refer java.util.logging.Level for different levels. For example FINE for more output while local development. |
Value | Description |
---|---|
json |
Will use org.echocat.tjl.JsonFormatter - see Available formatter for more information. |
text |
Will use org.echocat.tjl.TextFormatter - see Available formatter for more information. |
Name | Description | Default |
---|---|---|
org.echocat.tjl.Handler.level |
Minimum level of log entries to be logged/visible. Pleas refer java.util.logging.Level for more information. |
ALL |
org.echocat.tjl.Handler.formatter |
Formatter to format the message in the console. | org.echocat.tjl.JsonFormatter |
Name | Description |
---|---|
org.echocat.tjl.JsonFormatter |
Formats the whole output as JSON. One entry per line. |
org.echocat.tjl.TextFormatter |
Formats every entry per line in a simple way - better for local debugging. |
LOG_LEVEL=debug bin/catalina.sh run
LOG_FORMAT=text bin/catalina.sh run
tomcat-json-logging is an open source project by echocat. So if you want to make this project even better, you can contribute to this project on Github by fork us.
If you commit code to this project, you have to accept that this code will be released under the license of this project.
See the LICENSE file.