> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/6.19/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/tposs/6.19/configuration/logging.md).

# Logging configuration

TPOSS writes log messages into `stdout`. Use the following configuration options to control TPOSS logging:

```yaml
log:
  console:
    # Logging level for the TPOSS logger.
    level: info
    # Format of the TPOSS logs. The available formats are `default`, `json`, or a string that defines a custom format.
    format: default
    # Number of log messages in the TPOSS log handler queue after which it switches to the sync mode.
    sync_mode_queue_len: 500
    # Number of log messages in the TPOSS log handler queue after which it starts to drop the messages.
    drop_mode_queue_len: 500
    # Number of log messages in the TPOSS log handler queue after which it starts to flush the messages.
    flush_queue_len: 1000
    # Maximum number of log messages that can be handled within the time specified in **log.console.burst_limit_window_time**.
    burst_limit_max_count: 500
    # Time window in milliseconds during which the burst limit applies.
    # The burst limit is specified in **log.console.burst_limit_max_count**.
    burst_limit_window_time: 1000
```

## Log levels

These are the available TPOSS log levels ordered by importance:

- `emergency`
- `alert`
- `critical`
- `error`
- `warning`
- `notice`
- `info`
- `debug`

> [!CAUTION]
> The default values are set to work well in most cases. Think carefully before changing them, and consider the system's load and use case, as the values depend on both. If the log level is set to `debug`, you may need to increase these values to handle the higher log volume. Otherwise, it is recommended to keep them low to avoid log overload.

## Log format

The format of log messages is specified in the **log.console.format** configuration option. It can have one of these values:

- `json`
- `default`
- A string that defines a custom format

When the **log.console.format** configuration option is set to `json`, all TPOSS log messages are printed in the JSON format. If set to `default`, the log messages are printed according to the following template: `$time [$level] [code=$code] [node=$node] $msg`. The template may have variables prefixed with the `$` symbol. When the resulting log message is printed, each variable is replaced with its corresponding runtime value.

You can pass a custom format string to specify a template for log messages. The **log.console.format** supports the following variable names:

- `$time` - UTC timestamp of the log entry
- `$level` - [Log level](#log-levels)
- `$code` - Code number. For more information, see the [Log message codes](https://docs.cennso.com/components/tposs/6.19/troubleshooting/log-message-codes.md) document.
- `$msg` - Log message
- `$pid` - Process ID, which prints the log message
- `$node` - TPOSS node name

For example, if you want to have logs in the [logfmt](https://brandur.org/logfmt) format, configure TPOSS as follows:

```yaml
log:
  console:
    format: "time=$time level=$level code=$code node=$node msg=$msg"
```

This configuration prints log messages like:

```
time=2025-05-20T09:14:12.892442Z level=debug code=1000 node=nonode@nohost msg=Fetching metrics related to the data in the database
```

## Overload protection

Too many log messages may affect TPOSS performance and resource consumption. To prevent this, TPOSS provides several configuration options to control logging overload:

- **logging.console.burst_limit_max_count** - controls the maximum number of log messages that TPOSS handles within the time window defined in **logging.console.burst_limit_window_time** (in milliseconds). If the number of messages is bigger than this limit, additional messages are dropped until the time window resets.
- **log.console.sync_mode_queue_len** - defines the queue size threshold for switching to synchronous mode. By default, log messages are handled asynchronously. When the number of messages in the logger queue exceeds this value, synchronous handling is triggered. If the queue grows even further, TPOSS starts to drop and flush the messages. Such messages will never be printed. This behaviour is controlled by the **log.console.drop_mode_queue_len** and **log.console.flush_queue_len** configuration options. If **sync_mode_queue_len** equals **drop_mode_queue_len**, all the messages are handled asynchronously.

To ensure the overload protection mechanism works as expected, make sure the following condition is met:

```
sync_mode_queue_len ≤ drop_mode_queue_len ≤ flush_queue_len
```

For more information, read the [official Erlang logger documentation](https://www.erlang.org/doc/apps/kernel/logger_chapter.html).

If you experience issues with logging, such as performance degradation due to the high number of logs, refer to the [Preventing logs overload](https://docs.cennso.com/components/tposs/6.19/troubleshooting/logging.md) document. It provides instructions on how to adjust the logging level and change the configuration for logging overload at runtime.

> [!NOTE]
> Some of the logging messages may contain the `code` tag with the code number that describes an error or warning. For more information, see the [Log message codes](https://docs.cennso.com/components/tposs/6.19/troubleshooting/log-message-codes.md) document.
