Skip to content

Specifying Logger Configuration

vzakaznikov edited this page Jan 24, 2024 · 2 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.

Any custom logger configuration must at least define stdout and rotating_service_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_service_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_service_logfile

If the logger configuration is using a custom format for the rotating_service_logfile, then a custom logger_format object must be defined to specify the format of the service's 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