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:
[1]:
# configuration file with default values for logging setup.
from skyllh.core.config import (
Config,
)
# Logging setup utilities.
from skyllh.core.logging import (
get_logger,
setup_logger,
setup_logging,
)
The default configuration contains a logging field with default logging settings
[2]:
cfg = Config()
cfg
[2]:
{'multiproc': {'ncpu': None},
'logging': {'log_level': 'INFO',
'log_format': '%(asctime)s %(processName)s %(name)s %(levelname)s: %(message)s',
'enable_tracing': False},
'project': {'working_directory': '.'},
'repository': {'base_path': None, 'download_from_origin': True},
'units': {'internal': {'angle': Unit("rad"),
'energy': Unit("GeV"),
'length': Unit("cm"),
'time': Unit("s")},
'defaults': {'fluxes': {'angle': Unit("rad"),
'energy': Unit("GeV"),
'length': Unit("cm"),
'time': Unit("s")}}},
'datafields': {'run': 4,
'ra': 4,
'dec': 4,
'ang_err': 4,
'time': 4,
'log_energy': 4,
'true_ra': 8,
'true_dec': 8,
'true_energy': 8,
'mcweight': 8},
'caching': {'pdf': {'MultiDimGridPDF': False}}}
There are two functions that can be used to setup a logger:
setup_loggingin normal scripts should be used in analysis scripts by the usersetup_loggeris more advanced and can be used for custom handler behavior
Logger is setup with the following function call. Analyzer can define all desired logging properties. Required arguments are cfg and name. Remaining arguments default to what is defined in the config file if set to None.
[3]:
logger = setup_logging(
cfg=cfg,
name=__name__,
log_format='[%(asctime)s] %(name)s - %(levelname)s - %(message)s',
log_level='DEBUG',
console=True,
log_file=None,
reconfigure=False,
)
The important thing of setup_logging is that it takes care of setting up the skyllh package logger and the user-defined script logger by calling setup_logger twice.
In setup_logger, where some more arguments are available for advanced custom logging configuration.
setup_logger allows to define different logging levels for the console and log file, and may or may not propagate handlers to ancestor loggers. However, these settings are mostly not needed for the general user, and are therefore not exposed in any example scripts.
[4]:
logger = setup_logger(
cfg=cfg,
name=__name__,
log_format='[%(asctime)s] %(name)s - %(levelname)s - %(message)s',
log_level='DEBUG',
console=True,
console_level='DEBUG',
log_file=None,
file_level='DEBUG',
file_mode='a',
propagate=False,
clear_existing_handlers=False,
)
If a log_file name is passed, the file is created by default in the working directory defined in the configuration.
log_file absolute paths are also allowed.
To generate logs inside skyllh package one has to get the logger for the given class/function
[5]:
logger = get_logger(__name__)
To log an event we use the logging function of a desired level, e.g.:
[6]:
logger.warning('This is a warning.')
[2026-03-23 14:21:33,953] __main__ - WARNING - This is a warning.
The list of logging levels can be found here.