Logging

python-dockerflow provides a dockerflow.logging.JsonLogFormatter Python logging formatter that produces messages following the JSON schema for a common application logging format defined by the illustrious Mozilla Cloud Services group.

Configuration

Example configuration:

import logging.config

cfg = {
    'version': 1,
    'formatters': {
        'mozlog': {
            '()': 'dockerflow.logging.JsonLogFormatter',
            'logger_name': 'MyServiceName'
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'mozlog'
        },
    },
    'loggers': {
        'myservice': {
            'handlers': ['console'],
            'level': 'DEBUG',
        },
    }
}

logging.config.dictConfig(cfg)

logging.info('I am logging in mozlog format now! woo hoo!')

In this example, we set up a logger for myservice (you’d replace that with your service name) which has a single handler named console which uses the mozlog formatter to output log event data to stdout.

API

class dockerflow.logging.JsonLogFormatter(format=None, datefmt=None, logger_name='TestPilot')[source]

Log formatter that outputs machine-readable json.

This log formatter outputs JSON format messages that are compatible with Mozilla’s standard heka-based log aggregation infrastructure.

See also: https://mana.mozilla.org/wiki/display/CLOUDSERVICES/Logging+Standard https://mana.mozilla.org/wiki/pages/viewpage.action?pageId=42895640

Adapted from: https://github.com/mozilla-services/mozservices/blob/master/mozsvc/util.py#L106