Martin has posted 5 posts at DZone. You can read more from them at their website. View Full User Profile

Simplify Your Logging With Tinylog Version 0.6

  • submit to reddit

The first public beta of tinylog, a minimalist logger for Java, has released as version 0.6. The aim of the tinylog project is to simplify logging in Java, while limiting the consumption of resources to an absolute minimum.

The idea for tinylog arose from the experience of using log4j in several customer projects. Log4j is a very powerful logging framework that can be configured very precisely. However, in practice, only a small subset of these configuration options is usually used. Typically, in the server sector, where multiple threads work a long time in parallel and under a load, the use of log4j for detailed logging of events can lead to performance problems.

Tinylog follows the KISS principle ("Keep it simple, stupid") with the objective of avoiding unnecessary complexity. Opposite to log4j, tinylog has only one single logger that is static. So the usual creation of a logger instance for each class by Logger.getLogger(MyClass.class) is not necessary. In order to save time, the logger creation code is copied from another class, but this often leads to trouble — the software engineer can forget to change the class parameter, resulting in the wrong log entries.

import org.pmw.tinylog.Logger;

public class Application {

     public static void main(final String[] args) {
"My log entry");


Generated output:

2012-08-09 06:31:25 [main] Application.main()
INFO: My log entry

To reach the intended performance, the project includes a benchmark that measures the run time for creating 100,000 log entries in a single thread, as well as in ten parallel threads. In parallel logging threads, tinylog is 3.8 times faster than log4j; in a single thread, tinylog is 1.7 times faster. This is achieved inter-alia by precompiled patterns and use of synchronized resources, not blocking the whole logger.

Tinylog supports five different logging levels (from trace to error). The output of log entries can be configured depending on the logging level and the package that contains the class. Log entries can either be printed on the console or written in log files. Thereby the output format can be configured by patterns. For example, the location in the source code (class, method and line), where the log entry was created, as well as the date and time, can be automatically added to the output.
The logging methods of tinylog correspond to MessageFormat.format() of the JDK. Therefore log entries can be simply formatted and the text message will only be generated if the log entry is really output.

The JAR file of the logger has a size of only 14 KB. You can download it from Tinylog is an Open Source project and is published under the Apache License 2.0.

Published at DZone with permission of its author, Martin Winandy.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Peter Jodeleit replied on Thu, 2012/08/23 - 4:49pm

Just a (very) short look at the "main" class:

  1. A log writing thread with low priority
  2. Getting the loggers class and methode with "new Throwable().getStackTrace()[index]

Eventually the log is never written or (too) late. And messing with thread priority is seldom a good idea. I wonder if this is really so fast or if your benchmarks are just broken (like most micro benchmarks)?

Just my 2 cents, Peter

Martin Winandy replied on Fri, 2012/08/31 - 2:41pm

Hi Peter,

The writing thread is a new feature oft tinylog 0.7 and must be enabled by the user. The benchmark ( doesn't use the writing thread yet. A new (async) benchmark is in progress. Other logging frameworks have also similar functionality (known as AsyncAppender) and I want to create a fair comparison of the different implementations of async writing. The benchmark makes sure that all log entries are written by waiting for flush() and join() respectively.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.