GitHub

Update for Second Milestone

December 10, 2018

The version 2.0.0-M2.1 contains two fixes for the second milestone. tinylog can correctly parse parameters for multiple policies for rolling file writer now (see issue 84). In addition, animal sniffer annotations are not a required Maven dependency anymore.

Leave a comment

First Third-Party Logging APIs available for tinylog 2.0

November 24, 2018

In the second milestone, tinylog 2 supports the logging API of tinylog 1.3 and first third-party logging APIs. This includes a binding for SLF4J and a bridge for java.util.logging aka JUL. The support for all these logging APIs is provided by separate artifacts and can be integrated as needed.

tinylog’s binding for SLF4J is compatible with the versions 1.6 and 1.7, and has to be in the classpath together with slf4j-api. All log entries will be forwarded from org.slf4j.Logger to tinylog, and processed by the tinylog implementation like other log entries. Markers are mapped to tinylog’s tags. MDC and tinylog’s thread context share their data.

The bridge for forwarding log entries from java.util.logging.Logger to tinylog has to be activated explicitly. JUL doesn’t provide any API to do this automatically. tinylog’s bridge for JUL can be activated by calling org.tinylog.jul.JulTinylogBridge.activate() at the startup of your application, before issuing any log entries via java.util.logging.Logger.

To simplify the migration from tinylog 1.3 to tinylog 2, there is a reimplementation of the legacy logging API of tinylog. Thereby, applications can use both versions of tinylog’s logging API and all log entries will be handled by tinylog 2. This means that only one configuration is necessary.

Leave a comment

First Milestone of tinylog 2.0 is out

November 7, 2018

Today, after two years of development, it is time to release the first milestone of tinylog 2.0. All planned features are already implemented for tinylog itself. Third party logging APIs and implementations for web and application servers are scheduled for the coming milestones. Version 2.0 is a complete redevelopment with a modern architecture. API and implementation are now divided into two different JARs. tinylog will remain a lightweight and easy-to-use logging framework. tinylog will remain a lightweight and easy-to-use logging framework, with rarely used features replaced by new features requested by the community.

Tags for Log Entries

One of the most requested features was the support of tagged log entries. Tags can be output as part of the log entry, or used to output log entries via different writers. An instance of a tagged logger can be fetched from the static logger class. Depending on how often a tag is used, it is recommended to keep the tagged logger as a (member) variable, or to use the inline variant.

TaggedLogger logger = Logger.tag("SYSTEM"); // Get an instance of the tagged logger
logger.debug("Hello World!");
logger.error("An urgent problem occured");
Logger.tag("SYSTEM").info("Hello World!"); // Fluent API inline use

Tags are configured as self-explanatory via the property “tag”. As in the previous version, tinylog 2 can be configured via tinylog.properties. However, the prefix “tinylog.” is omitted to shorten the number of keystrokes in the new version.

writer        = console
writer.tag    = SYSTEM
writer.format = {date} - {tag} - {message}

File Writer Improvements

By default, tinylog use the default charset of the current operating system for writing log entries to files. In tinylog 2, the charset is configurable, and every charset supported by the current JVM can be used.

writer         = file
writer.file    = test.txt
writer.charset = UTF-8

The rolling file writer is used if a new log file should be started after defined events. For example, when a certain file size is reached or at a fixed time. In tinylog 2, the rolling file writer supports patterns for the file names of log files.

writer          = rolling file
writer.file     = logs/{date:yyyy}/{date:MM}/myapp-{count}.log
writer.policies = daily

Further Minor Changes

The base package name of tinylog has now been shortened from org.pmw.tinylog to just org.tinylog, and the severity level WARNING is just WARN. The new names are easy to remember and save some typing time. To make the API of the logger class clearer, all public methods not related to logging have been removed. Now tinylog 2 is compiled with debug information (as is common nowadays), which simplifies debugging significantly.

The previous version of tinylog could only support system properties and environment variables for resolving file names in the properties file. tinylog 2 supports both in all values, and uses a distinct syntax to distinguish between system properties and environment variables.

writer          = file
writer.file     = ${HOME}/application.log  # Environment variable
writer.format   = #{user.name}: {message}  # System property

Dropped Features

The recommended way to configure tinylog is using properties files. The fluent API for configuration has been dropped, as it was rarely used in real world projects. Configuration can still be set at runtime by using the configuration class. This can be done property based by using the same keys and values as for tinylog.properties.

For performance reasons, the configuration in tinylog 2 is immutable, as opposed to the previous version of tinylog. As soon as the first logging method is called, the configuration cannot be changed.

Leave a comment