I did not find anything to suit my needs. Hence I created a small open source library called log4j-weblayout
.
There is a org.apache.log4j.HTMLLayout
in log4j but I did not find it useful. All it does is dump your statements in a HTML table. While this is better than text dump it doesn't utilize HTML features such as font colors and popup windows.
For introduction and usage information take a look at the project website.
List of features (will be updated as more are added):
- Better timestamp handling. Major source of verbosity in log files is the repeating timestamp. Text based files have complete timestamp for each log statement like:
Sat Jul 23 2005 02:16:57 150ms
. This increases the verbosity. If you print a shorter form like02:16:57
you loose essential details. Weblayout hits the sweet spot by printing the concise readable form and showing full date in a mouse over popup. - Distinguishing levels by color coding. The statements from different levels stand out from each other.
- Switching log level at runtime. With text files you set the log level before running the application. You cannot change the level while viewing the log. Weblayout provides a small toolbox at the top of the screen that toggles the levels by using Javascript.
- Better exception handling. Combines multiple exceptions together to display a single coherent description of the problem. For example it would merge
ConnectException
,IllegalArgumentException
andParseException
into something like:Did not receive response from server, because The request is not valid, because Date cannot be in the past
. - Better stack trace handling. By default
logger.info(exception)
will log only message and not stacktrace. If you manually extract stacktrace as a string and pass it to log4j, it would not be very readable. log4j-weblayout will do this automatically and pretty print it in the same way that your IDE does.