Simple Logger

Discord Source API Docs Issues Releases
Discord GitHub Javadoc GitHub



This is a SLF4J logger that logs to System out JSON structured log messages. It can also log plan text messages typically for development use when running tests.

It is designed to be used by applications that will be run in K8s or Lambda.


Dependency

Add avaje-simple-logger as a dependency.

<dependency>
  <groupId>io.avaje</groupId>
  <artifactId>avaje-simple-logger</artifactId>
  <version>{simple-logger.version}</version>
</dependency>

avaje-logger.properties

Add a src/main/resources/avaje-logger.properties to configure the logger.

## specify the default log level
logger.defaultLogLevel=warn

## specify some log levels
log.level.com.foo.bar=DEBUG
log.level.io.avaje=INFO

avaje-logger-test.properties

For testing, we might desire to log in a plain format rather than JSON format. We also might want to define some test specific log levels.

Add a src/test/resources/avaje-logger-test.properties to configure the logger when running tests.

## for testing we desire plain format than json format
logger.format=plain

## default log level to use when running tests
logger.defaultLogLevel=INFO

## some test specific log levels
log.level.io.ebean.test.containers=TRACE
log.level.io.ebean.DDL=TRACE
#log.level.io.ebean.SQL=DEBUG
#log.level.io.ebean.TXN=DEBUG

Debugging

To debug avaje-simple-logger set the log level for io.avaje.simplelogger to DEBUG.

log.level.io.avaje.simplelogger=DEBUG

If you are also using io.avaje:avaje-aws-appconfig, then you can additionally set io.avaje.config to TRACE.

log.level.io.avaje.config=TRACE

Configure

Configure the logger via main resource avaje-logger.properties and test resource avaje-logger-test.properties

## specify the default log level to use
logger.defaultLogLevel=warn

## specify to log as `json` or `plain` format (defaults to json)
#logger.format=json
logger.format=plain

## specify if the logger name is abbreviated. Values:
## - full - use the full logger name
## - short - use the class name / suffix part of the logger name after the last `.`
## - (some integer e.g. 100) - abbreviate the logger name to the target length (shorten the package names)

#logger.nameTargetLength=full
#logger.nameTargetLength=short
#logger.nameTargetLength=100

logger.nameTargetLength=100

## specify an explicit timezone to use, defaults to using default timezone
logger.timezone=UTC

## specify an explicit timestamp format to use, defaults to ISO_OFFSET_DATE_TIME
## valid values: ISO_OFFSET_DATE_TIME, ISO_ZONED_DATE_TIME, ISO_LOCAL_DATE_TIME, ISO_DATE_TIME, ISO_INSTANT
logger.timestampPattern=ISO_OFFSET_DATE_TIME

Structured JSON

By default, the log format is JSON. Example:

{
  "component":"my-application",
  "env":"dev",
  "timestamp":"2025-07-14T13:44:44.230959+12:00",
  "level":"TRACE",
  "logger":"io.avaje.config",
  "message":"load from [resource:application-test.properties]",
  "thread":"main"
}

component

A component key value is added if:

Examples:

## a literal value
logger.component=my-application

## uses system property SERVICE_NAME or environment variable SERVICE_NAME
logger.component=${SERVICE_NAME}

## uses system property service.name or environment variable SERVICE_NAME
logger.component=${service.name}

env

An env key value is added to represent the environment the application is running in.

An env key value is added automatically if:

Examples:

## uses system property `app.env` or environment variable `APP_ENV`, defaults to `localdev`
logger.environment=${app.env:localdev}

## literal value
logger.environment=DEV

Dynamic log levels

avaje-simple-logger automatically registers with avaje-config such that any configuration changes that start with log.level. are logging level configuration changes, and these are applied.

avaje-config supports plugins like AWS AppConfig, where configuration changes can be dynamically made to the application. For example, log.level. changes can be dynamically made this way.

Don't need dynamic configuration?

If an application does not need dynamic configuration, then we can just use avaje-simple-json-logger. This excludes the avaje-config dependency.

<dependency>
  <groupId>io.avaje</groupId>
  <artifactId>avaje-simple-json-logger</artifactId>
  <version>1.0/version>
</dependency>

Note that log levels can still be modified programmatically via:

Map<!String>, String> nameLevels = new HashMap<>();
nameLevels.put("com.foo", "debug");
nameLevels.put("com.foo.bar", "info");

LoggerContext.get().putAll(nameLevels);