Logging

All Hazy services have a configurable logging system that allows the operator to specify location, log level, and format of operational logs.

Hub and synth

The hub and (if running synth separately, i.e, using the distributed architecture) synth allow a user to pass in a custom logging config file as follows.

  1. Ensure the config file is available within the docker container, this may involve using the docker volume mount option or mounting a config map if using kubernetes.
  2. Set the HAZY_LOG_CONF environment variable for the container to point to the log config within the mounted volume.

The Hazy containers use python logging and so the following can be used as a reference for the log file content.

https://docs.python.org/3/library/logging.config.html#logging-config-fileformat

In addition, Hazy provides a custom formatter for JSON output. The following snippet provides an example of how to utilise the json formatter in a logging config.

{
    "version": 1,
    "disable_existing_loggers": false,
    "formatters": {
        "json": {
            "()": "hazy_configurator.utils.hazy_logger.HazyJsonLogger",
            "datefmt": "%Y-%m-%dT%H:%M:%S%z" // optional
        }
    },
    "handlers": {
        "jsonstdout": {
            "class": "logging.StreamHandler",
            "level": "INFO",
            "formatter": "json",
            "stream": "ext://sys.stdout"
        }
    },
    "root": {
        "level": "INFO",
        "handlers": [
            "jsonstdout"
        ]
    }
}

JSON logging formatter config options

  • datefmt date format string for log entries.
  • sloc_info enable source code file and line info.
  • ex_info enable full stack traces when logging exceptions.

Keycloak

Keycloak instructions for customising logging, including setting log format to JSON for simplified aggregation can be found here:

https://www.keycloak.org/server/logging

Logging