eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

1. Overview

tinylog is a lightweight logging framework for Java applications and Android apps. In this tutorial, we’ll see how to issue log entries with tinylog and how to configure the logging framework. Some approaches of tinylog are very different from Log4j and Logback, as we’ll see.

2. Get Started

First, we need to add the dependencies for the tinylog API and tinylog implementation to the pom.xml file:

<dependency>
    <groupId>org.tinylog</groupId>
    <artifactId>tinylog-api</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.tinylog</groupId>
    <artifactId>tinylog-impl</artifactId>
    <version>2.5.0</version>
</dependency>

Now, let’s create a new Java application and add a log statement:

package com.baeldung.tinylog;

import org.tinylog.Logger;

public class Application {

    public static void main(String[] args) {
        Logger.info("Hello World!");
    }
}

Unlike other logging frameworks, tinylog has a static logger class. Therefore, we don’t have to create a logger instance for each class in which we want to use logging. This saves us some boilerplate code. Nevertheless, tinylog can output log messages along with source code location information.

For example, if we execute our application without any configuration, the log message will be output to the console by default:

2023-01-01 14:17:42 [main] com.baeldung.tinylog.Application.main()
INFO: Hello World!

3. Logging

Usually, we want to log more than just static text, unlike what we did in the previous example. tinylog has various logging methods for different use cases. Each logging method exists for all five supported severity levels: trace(), debug(), info(), warn(), and error(). For the sake of readability, we’ll always use only one of them in the examples.

3.1. Placeholders

We can use text with placeholders to assemble the log message at runtime:

Logger.info("Hello {}!", "Alice"); // Hello Alice!

When logging numbers, we can format them exactly the way we want. For example, let’s output π with two decimal places:

Logger.info("π = {0.00}", Math.PI); // π = 3.14

tinylog supports lazy logging by using lambdas. If a log message or a placeholder argument is passed as lambda, it will only be resolved if the severity level is enabled. Lazy logging using lambdas can significantly improve performance if a severity level is known to be disabled in production:

Logger.debug("Expensive computation: {}", () -> compute());

3.2. Exceptions

In tinylog, exceptions are always the first argument when issuing log entries to prevent exceptions from being mixed with placeholder arguments:

try {
    int i = a / b;
} catch (Exception ex) {
    Logger.error(ex, "Cannot divide {} by {}", a, b);
}

Nevertheless, it’s also perfectly legal to log an exception without any explicit log message. In this case, tinylog automatically uses the message from the exception:

try {
    int i = a / b;
} catch (Exception ex) {
    Logger.error(ex);
}

4. Configuration

The recommended way to configure tinylog is to use a properties file. At startup, tinylog automatically looks for tinylog.properties in the default package and loads the configuration from this file. The correct location for tinylog.properties is normally src/main/resources. However, this may depend on the build tool used.

4.1. Console

In Java applications, tinylog outputs log entries to the console by default. However, we can also explicitly configure a console writer and customize the output.

Let’s enable the console writer for all log entries with the severity level info and higher. This means that trace and debug log entries aren’t output:

writer       = console
writer.level = info

As we’ve seen earlier, tinylog outputs all log entries as two-liners by default. So, let’s define a custom format pattern that can output log entries in a single line:

writer        = console
writer.format = {date: HH:mm:ss.SSS} [{level}] {class}: {message}

The {class} placeholder outputs the fully-qualified name, the {level} placeholder the severity level of the log entry, the {date} placeholder the date and/or time, and the {message} placeholder the log message (and exception if present).

For formatting dates and times, tinylog uses SimpleDateFormat or DateTimeFormatter, depending on the Java version. So, we can use all date and time patterns that these Java classes support.

When we execute our application from earlier now, we’ll see log output on the console:

14:17:42.452 [INFO] com.baeldung.tinylog.Application: Hello World!

4.2. Log Files

tinylog has four different file writers. In practice, the rolling file writer is usually the one used in real applications. Therefore, this tutorial focuses on this writer.

The rolling file writer can start new log files at defined events. For example, let’s configure a writer that starts a new log file at startup and every day at 6 am:

writer          = rolling file
writer.file     = logs/myapp_{date: yyyy-MM-dd}_{count}.log
writer.policies = startup, daily: 06:00
writer.format   = {class} [{thread}] {level}: {message}

For the log file path, we should use placeholders to avoid overwriting existing log files. In the above configuration, we use a placeholder for the date and another for a sequential count number. For example, if we start the application multiple times on January 1, 2023, the first log file will be logs/myapp_2023-01-01_0.log, the second one will be logs/myapp_2023-01-01_1.log, and so on.

The policies are the defined events at which a new log file should be started. The format pattern for log entries can be freely configured in the same way as for the console writer.

For saving space on the file system, we can also compress log files and limit the number of log files to be stored:

writer         = rolling file
writer.file    = logs/myapp_{date: yyyy-MM-dd}_{count}.log
writer.convert = gzip
writer.backups = 100

When gzip compression is enabled, the current log file is still a plain uncompressed text file. However, as soon as tinylog starts a new log file, the logging framework compresses the previous log file with gzip and adds .gz as the file extension. If there are more than 100 compressed backup files, tinylog starts deleting the oldest to ensure that there are never more than 100 files present.

4.3. Logcat

In Android apps, tinylog outputs log entries via Logcat by default. However, we can also explicitly configure a Logcat writer and customize the output.

First, let’s create a main activity that issues a log entry that we can use as a basis for future configuration:

package com.baeldung.tinylog;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import org.tinylog.Logger;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Logger.info("Hello World!");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Now, we can enable the Logcat writer, for example, for all log entries with the severity level debug and higher. This means that trace log entries aren’t output:

writer       = logcat
writer.level = debug

tinylog can automatically compute the tag, which we’d normally have to pass as the first parameter when using Android’s Log class. By default, the logging framework uses the simple class name without the package name as the tag. For example, tinylog uses MainActivity as the tag for all log entries issued in the class com.baeldung.tinylog.MainActivity.

However, the tag computation is freely configurable. For example, if we use a tagged logger instead of the static logger, we can use the tinylog tag also as the Logcat tag:

public class MainActivity extends AppCompatActivity {

    private final TaggedLogger logger = Logger.tag("UI");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        logger.info("Hello World!");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Now, we can reconfigure our Logcat writer to use the UI tag of the tagged logger:

writer         = logcat
writer.tagname = {tag}

4.4. Multiple Writers

We can use multiple writers at the same time in tinylog. One way we can configure multiple writers is to number them consecutively:

writer1       = console
writer1.level = debug

writer2       = rolling file
writer2.file  = myapp_{count}.log

However, we can also name our writers meaningfully:

writerConsole       = console
writerConsole.level = debug

writerFile          = rolling file
writerFile.file     = myapp_{count}.log

tinylog recognizes every property name that starts with writer. However, every writer must have a unique property name to comply with the Java standard for properties files.

4.5. Asynchronous Output

To avoid blocking the application when log entries are output, tinylog can output log entries asynchronously. This is especially recommended when using file-based writers.

We only need to enable the writing thread in our tinylog configuration to benefit from asynchronous output:

writingthread = true

With this configuration, tinylog uses a separate thread for outputting log entries.

Additionally, we can also further improve the performance of rolling file writers by enabling buffered output. By default, file-based writers write each log entry to the log file separately. However, with buffered output, tinylog can output multiple log entries to the log file in a single IO operation:

writer          = rolling file
writer.file     = myapp_{count}.log
writer.buffered = true

5. Conclusion

In this article, we’ve discussed the fundamental logging methods and configuration parameters of tinylog 2. We focused on features that are most commonly used in real applications. Furthermore, tinylog offers many more features, which we can discover in the official documentation.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (All)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)