Skip to main content
Version: 2.x

Configuration Keys Reference

Each built-in logger reads its settings from a configuration source through ZIO Config. This page lists every key for the console logger, the file logger, and the level filter they share. The keys are relative to a root path, which is logger by default. Each feature has its own page with examples: Console Logger, File Logger, and Log Filter.

Default Config Pathโ€‹

The default root path lives in zio.logging.loggerConfigPath, as the single segment logger. The ConsoleLoggerConfig.load, ConsoleLoggerConfig.make, FileLoggerConfig.load, and FileLoggerConfig.make functions, and the logger layers such as zio.logging.consoleLogger and zio.logging.fileLogger, read from this path unless you pass another path. The source declares the value as follows:

val loggerConfigPath: NonEmptyChunk[String] = NonEmptyChunk("logger")

A custom path is a NonEmptyChunk[String]. The first element is the top-level key, and the remaining elements are nested keys under it. For example, NonEmptyChunk("app", "logging") reads the keys from app.logging.

Console Logger Keysโ€‹

The console logger config is zio.logging.ConsoleLoggerConfig. It has a format and a level filter. The table lists its keys under the root path.

KeyTypeDefaultMeaning
formatFormat stringLogFormat.defaultThe layout of each line. The string form is described in Formatting Log Records.
filter.rootLevelLog level nameINFOThe minimum level for every logger name that has no mapping.
filter.mappingsTable of logger name to log levelEmpty tableMinimum levels for logger names. A key is a dot-separated logger name, which also covers the names under it, or a glob pattern; see Log Filter.

File Logger Keysโ€‹

The file logger config is zio.logging.FileLoggerConfig. It adds a destination path and the options for writing and rolling the file. The table lists its keys under the root path.

KeyTypeDefaultMeaning
pathURI string, such as file:///var/log/app.logNone, requiredThe file to write. The value is read with URI.create, so it must be a URI, not a plain path. An invalid value fails the config load.
formatFormat stringLogFormat.defaultThe layout of each line. See Formatting Log Records.
filter.rootLevelLog level nameINFOThe minimum level for every logger name that has no mapping.
filter.mappingsTable of logger name to log levelEmpty tableMinimum levels for logger names, with the same rules as the console logger.
charsetCharset name, such as UTF-8UTF-8The character encoding of the file. The name is read with Charset.forName, and an unknown name fails the config load.
autoFlushBatchSizeInteger1The number of lines written before the writer flushes its buffer. The value 1 flushes after every line. Use 1 or more; see Flushing and Write Errors.
bufferedIOSizeIntegerNone, unbufferedWhen set, the writer wraps the file in a java.io.BufferedWriter with a buffer of this many characters.
rollingPolicy.typeRolling policy nameNone, no rollingWhen set, the file rolls over with the rolling policy. The only supported value is TimeBasedRollingPolicy.

The rollingPolicy.type key is optional. When the key is absent, the file is not rolled.

Log Level Filter Keysโ€‹

The level filter config is zio.logging.LogFilter.LogLevelByNameConfig. The console and file loggers read it under the filter key, so the full keys are filter.rootLevel and filter.mappings. The class and its helper methods are described in LogFilter and LogGroup Reference.

KeyTypeDefaultMeaning
rootLevelLog level nameINFOThe minimum level for every event that matches no mapping.
mappingsTable of logger name to log levelEmpty tableMinimum levels for logger names. Dot-separated names select the mapping. The matching rules are described in Log Filter.

Config Descriptors and Equal Instancesโ€‹

The layers and the ConsoleLoggerConfig.load and FileLoggerConfig.load functions are built on public values that you can also use directly. ConsoleLoggerConfig.config, FileLoggerConfig.config and the other descriptors below are ZIO Config descriptors for the keys in the tables above. A descriptor is not nested under any path; ConsoleLoggerConfig.load and FileLoggerConfig.load nest it under the root path for you. Use a descriptor when the logger settings are part of a larger config type of your own, or when you need the config value without building a logger. ConsoleLoggerConfig.equal and the other Equal values below are ZIO Prelude Equal instances, which ReconfigurableLogger.make needs to decide whether a reloaded config has changed.

MemberTypeDescription
ConsoleLoggerConfig.defaultConsoleLoggerConfigLogFormat.default with LogFilter.LogLevelByNameConfig.default, which has root level INFO and no mappings.
ConsoleLoggerConfig.configConfig[ConsoleLoggerConfig]Reads format (default LogFormat.default) and the filter keys.
ConsoleLoggerConfig.equalEqual[ConsoleLoggerConfig]Two configs are equal when their formats are equal (==) and their filters are equal.
FileLoggerConfig.configConfig[FileLoggerConfig]Reads every key in File Logger Keys, with the defaults listed there.
FileLoggerConfig.equalEqual[FileLoggerConfig]Two configs are equal when the destination, charset, autoFlushBatchSize, bufferedIOSize, rolling policy, format and filter are all equal.
FileLoggerConfig.FileRollingPolicy.configConfig[FileLoggerConfig.FileRollingPolicy]Reads the type key. The only accepted value is TimeBasedRollingPolicy; any other value fails the config load.
LogFilter.LogLevelByNameConfig.configConfig[LogFilter.LogLevelByNameConfig]Reads rootLevel (default INFO) and mappings (default empty).
LogFilter.LogLevelByNameConfig.equalEqual[LogFilter.LogLevelByNameConfig]Structural equality of the root level and the mappings.

FileLoggerConfig is defined on every platform, but FileLoggerConfig.config turns the path value into a file path with java.nio.file.Paths, which Scala.js does not provide. File configuration is therefore usable on the JVM and Scala Native only, the same platforms that have the file loggers.

To read the console logger settings as one field of an application config, nest the descriptor under the key you choose:

import zio.{ Config, ZIO }
import zio.logging.ConsoleLoggerConfig

case class AppConfig(port: Int, logging: ConsoleLoggerConfig)

val appConfig: Config[AppConfig] =
(Config.int("port") ++ ConsoleLoggerConfig.config.nested("logging")).map { case (port, logging) =>
AppConfig(port, logging)
}

val loadAppConfig: ZIO[Any, Config.Error, AppConfig] = ZIO.config(appConfig)

With this descriptor, the logger keys are logging.format, logging.filter.rootLevel and logging.filter.mappings, next to the application's own port key.

Log Level Namesโ€‹

Every level key accepts the names below. ZIO's Config.logLevel reader accepts them case-insensitively, so info and INFO both parse.

NameLevel
ALLEvery event
TRACETrace
DEBUGDebug
INFOInfo
WARNWarning
ERRORError
FATALFatal
OFFNo events

The name WARNING is not accepted. Use WARN.

Complete Exampleโ€‹

The following HOCON configures the console logger with a custom level for one package. Only the keys in the tables above appear:

logger {
format = "%timestamp %level %name %message %cause"

filter {
rootLevel = INFO

mappings {
"zio.logging.example" = "DEBUG"
}
}
}

The file logger takes the same keys under a separate path, such as logger-file, when you pass that path to FileLoggerConfig.make:

logger-file {
path = "file:///var/log/app.log"
charset = "UTF-8"
autoFlushBatchSize = 100
bufferedIOSize = 8192

rollingPolicy {
type = TimeBasedRollingPolicy
}

filter {
rootLevel = INFO
}
}

This example trades safety for throughput: with autoFlushBatchSize = 100, up to 99 lines can still be in the buffer when the application stops, and the logger does not flush them at shutdown.

ZIO Chat

๐ŸŽ‰ Hey there, ZIO aficionado! ๐ŸŽ‰ Step into the ZIO wonderland with me as your guide. Whether you're a functional fanatic or just dipping your toes into the ZIO ecosystem, I'm here to make your journey smooth. Got ZIO questions? I've got answers! Let's navigate the ZIO universe together and unlock its infinite possibilities!