Over a million developers have joined DZone.

Simplify Your Logging With Tinylog Version 0.6


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) {
          Logger.info("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 www.tinylog.org/download. Tinylog is an Open Source project and is published under the Apache License 2.0.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}