Logging

Introduction

Logging is implemented using standard Python logging module. skyllh package adds support to multiprocessing logging.

Setup

Analyzer has to set up the main logger and at least one handler for it. Necessary imports:

[ ]:
import logging

# Logging setup utilities.
from skyllh.core.debugging import (
    setup_logger,
    setup_console_handler,
    setup_file_handler
)

Logger is setup with the following function call. Analyzer can define a desired logging level which optimally is infimum of handling levels.

[ ]:
setup_logger('skyllh', logging.DEBUG)

Log format is defined by a string containing LogRecord attributes.

[ ]:
log_format = '%(asctime)s %(processName)s %(name)s %(levelname)s: '\
             '%(message)s'

Console handler is used to print logs to the console.

[ ]:
setup_console_handler('skyllh', logging.INFO, log_format)

File handler is used to print logs to the specified file. By default it is created in the current working directory.

[ ]:
setup_file_handler('skyllh', logging.DEBUG, log_format, 'debug.log')

Generating logs

To generate logs inside skyllh package one has to

[ ]:
import logging

and get the logger for each class/function using:

[ ]:
logger = logging.getLogger(__name__)

To log an event we use the logging function of a desired level, e.g.:

[ ]:
logger.warning("This is a warning.")

The list of logging levels can be found here.