Skip to content

Specifying Logger Configuration

Vitaliy Zakaznikov edited this page Mar 24, 2025 · 3 revisions

You can specify a custom logger configuration using a configuration file.

✋ Note: A custom logger configuration can only be specified using a configuration file. See Using a Configuration File for more details.

The logger configuration is specified in the configuration file using the logger_config object. For more information about the logger configuration, see Configuration dictionary schema in the Python documentation.

❗Warning: Starting with version >= 1.8 rotating_service_logfile handler was renamed to rotating_logfile and this handler is mandatory.

Any custom logger configuration must at least define stdout and rotating_logfile handlers as well as configure testflows.github.hetzner.runners in the loggers.

For example,

config.yaml:
config:
   # logging module config
   logger_config:
       version: 1
       disable_existing_loggers: false
       formatters:
           standard:
               format: "%(asctime)s %(levelname)s %(funcName)s %(message)s"
               datefmt: "%m/%d/%Y %I:%M:%S %p"
       handlers:
           stdout:
               level: INFO
               formatter: standard
               class: testflows.github.hetzner.runners.logger.StdoutHandler
               stream: "ext://sys.stdout"
           rotating_logfile:
               level: DEBUG
               formatter: standard
               class: testflows.github.hetzner.runners.logger.RotatingFileHandler
               filename: /tmp/github-hetzner-runners.log
               maxBytes: 10485760
               backupCount: 1
       loggers:
           testflows.github.hetzner.runners:
               level: INFO
               handlers:
                   - stdout
                   - rotating_logfile

If the logger configuration is using a custom format for the rotating_logfile, then a custom logger_format object must be defined to specify the format of the rotating log file, which is needed for the service log and cloud log commands.

For the example above, the custom logger_format is the following:

config:
    # logger format
    logger_format:
        delimiter: " "
        default:
            - column: date
            - column: time
            - column: time_ampm
            - column: level
            - column: funcName
            - column: message
        columns:
            - column: date
              index: 0
              width: 10
            - column: time
              index: 1
              width: 8
            - column: time_ampm
              index: 2
              width: 2
            - column: level
              index: 3
              width: 8
            - column: funcName
              index: 4
              width: 15
            - column: message
              index: 5
              width: 80

Note that the date, time, and time_ampm columns come from the datefmt definition, which defines the asctime as a three-column field consisting of date, time, and time_ampm columns separated by a space.

datefmt: "%m/%d/%Y %I:%M:%S %p"
Clone this wiki locally