MentaLog is a straightforward logging library that stays out of the way and gets the job done with the beauty of simplicity. It is also very fast and produces ZERO garbage.
In a nutshell, it offers:
package org.mentalog; import static org.mentalog.Log.*; // to use MentaLog that's all you have to do! public class QuickStart { public static void main(String[] args) { // by default, logs go to the console Warn.log("This is a log message!", "user=", "foo", "age=", 21); // System.out output: // 21:11:17.263-WARN This is a log message! user=foo age=21 // or you can use placeholders: Warn.log("This is a log message! user={} age={}", "foo", 21); // System.out output: // 21:11:18.263-WARN This is a log message! user=foo age=21 // if you want to color you logs by level, you can: Log.setColors(true); Fatal.log("This is a log message! user={} age={}", "foo", 21); // System.out output in RED: // 21:11:17.263-FATAL This is a log message! user=foo age=21 // logging to a file: (files cannot support colors so the colors flag above will be ignored) Log.setFile(true); // a file Warn.log in the current directory will be created (or opened in append mode): Warn.log("Hello there!", "msg=", "hi"); // contents written to file: // LOG OPENED - 19/09/2011 21:15:42.627 // 21:15:42.630 Hello there! msg=hi // if you want to change the directory where the file will be created: Log.setDir("/var/log/myLogs"); // you can also roll the file whenever you want... Warn.roll(); // setting the log level Log.setLevel(Debug); // the levels are Debug, Info, Warn, Error, Alert and Fatal // or if you want to just enable or disable a single level Error.enable(true); // no matter what the level is, it will be logged Error.enable(false); // not matter what the level is, it will NOT be logged Error.enable(null); // go by the current log level // creating your own log files Logger audit = Log.createLogger("/var/log/myLogs" /* log dir */, "audit" /* filename */, false /* isSynchronized */, true /* asynchronous */); audit.log("This is a log message!", "user=", "foo", "age=", 21); // prints to the file /var/log/myLogs/audit.log: // 21:11:17.263 This is a log message! user=foo age=21 // you can also roll and close your audit log whenever you want: audit.roll(); audit.close(); } }