Skip to content
Download

Logger Options

Mach’s built-in logger can be configured during application startup using AppBuilder::configureLogging().

Settings that you do not explicitly change keep their default values.

Use configureLogging() to customize logger behavior:

mach::AppBuilder builder;
builder.configureLogging([](mach::LoggerOptions& options) {
options.enableColors = false;
options.logLevel = mach::LogLevel::Debug;
});

The logLevel determines the minimum severity required for a message to be written.

Messages below the configured level are ignored.

The default is:

mach::LogLevel::Info

For example, to include debug messages:

builder.configureLogging([](mach::LoggerOptions& options) {
options.logLevel = mach::LogLevel::Debug;
});

The pattern determines the format of each log message written by the logger.

Mach uses spdlog’s pattern syntax, where sequences beginning with % are replaced with information about the log entry.

The default pattern is:

[%Y-%m-%d %H:%M:%S] [%^%l%$] %v

For example, it can produce output similar to:

[2026-09-15 18:00:00] [info] Starting Mach server at http://127.0.0.1:3143

The default pattern is composed of several format specifiers:

Specifier Meaning
%Y Four-digit year.
%m Month.
%d Day of the month.
%H Hour in 24-hour format.
%M Minute.
%S Second.
%l Log level.
%v Log message.
%^ Begins log-level color formatting.
%$ Ends log-level color formatting.

Everything else in the pattern, such as brackets, spaces, hyphens, and colons, is written literally.

For example, to display only the time, log level, and message:

builder.configureLogging([](mach::LoggerOptions& options) {
options.pattern = "[%H:%M:%S] [%l] %v";
});

This produces output similar to:

[18:00:00] [info] Starting Mach server at http://127.0.0.1:3143

Mach supports spdlog’s pattern formatting syntax, so the pattern can be customized further when needed.

The enableColors option determines whether supported output includes ANSI colors.

The default is:

true

To disable colors:

builder.configureLogging([](mach::LoggerOptions& options) {
options.enableColors = false;
});

Disabling colors can be useful when logs are redirected to files or consumed by environments that do not support colored output.


For the complete logger configuration API, see LoggerOptions.