[slf4j-dev] ConsoleLogger proposal: No more excuses for System.out.println()

Tactonom Calendar tact.cal at yahoo.com
Sat Sep 1 14:35:03 CEST 2018


Please consider the following fork of SimpleLogger that is aimed to minimize the effort of using loggers for ad-hoc debugging instead of using System.out.println().

Source code and documentation are available at: https://github.com/alexander233/ConsoleLogger A jar file can be downloaded from http://www.inventivio.com/softblocks/slf4j-console-1.8.0-beta.jar

ConsoleLogger adds the following features to increase ease of use: 

- Output is optimized to minimize clutter when logging to the console (short log messages, levels are single-character ('d' instead of 'DEBUG'), fixed-column width approach for logger name, level, and time (optional) ensures that the actual content of the log messages starts at the same character position in every line; warn and error are sent to error console, other levels are sent to system console). 

- Users don't need to worry about directory hell when configuring log files (for many developers this is a real source of confusion when switching to a logging framework). Instead, logger configuration is stored seamlessly via Java Preferences. A minimal GUI is embedded in the Jar file; users can double-click the jar file and specify the loggers (of course, configuration via properties files and from the command line is supported, too). 

- Logger configuration is quick and concise. Neither the GUI nor the properties files require long-prefixes such as 'org.slf4j.consolelogger.' to which the fully qualified class name of the logger needds to be appended. Loggers can often be specified by writing only the short class name into a line (=> the package name will be 'inherited' from prior line; in the same way, the level can be omitted (if not specified it is also taken from earlier lines). This makes the logger configuration much more easy to read and quicker to write. 

- String expansion of variables passed into a log message is improved to work around shortcomings of Java's toString() method. Double values are only printed with 6 decimals instead of the overly long, hard to read 17 decimals that the JRE often provides (0.052632 instead of 0.05263157894736842). Old Java Date values are much better formatted ("2017-09-29" instead of "Fri Sep 29 00:00:00 CEST 2017"). Similar improvements for a few other classes (Point, Rectangle, Color, etc.). 

Overall, I believe that these features should lower the barriers towards using the powerful Slf4j logging framework significantly and eliminate any reason left for ad-hoc debugging the old way with System.out.println(). 

Note: Windows users may get 2 misleading Preferences-related warning messages in their console at startup. This is a known JRE bug that has been fixed in JRE 9 and a simple workaround exists (see the end of the ReadMe on Github).  

Best regards, 
  Alexander

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-dev/attachments/20180901/309dc246/attachment.html>


More information about the slf4j-dev mailing list