Source code for ska_sdp_piper.piper.utils.log_util

import copy
import logging

import dask
from distributed import WorkerPlugin
from ska_ser_logging import configure_logging

from ska_sdp_piper.piper.utils.log_config import LOGGING_CONFIG


[docs] class LogUtil: verbose = False
[docs] @classmethod def configure(cls, log_file=None, verbose=False): """ Configure the log using standardised config Parameters ---------- log_file: str Path to log file verbose: bool Set log verbosity to DEBUG """ level = logging.INFO if verbose: level = logging.DEBUG cls.verbose = verbose configure_logging( level=level, overrides=cls.__additional_log_config(log_file), )
@classmethod def __additional_log_config(cls, log_file): """ Get updated log configuration Parameters ---------- log_file: str Path to log file Returns ------- dictionary config """ config_with_file = { "handlers": { "file": { "()": logging.FileHandler, "formatter": "default", "filename": log_file, } }, "root": { "handlers": ["console", "file"], }, } config = copy.deepcopy(LOGGING_CONFIG) if log_file is None: return config config["handlers"] = { **config["handlers"], **config_with_file["handlers"], } config["root"] = config_with_file["root"] return config
[docs] class LogPlugin(WorkerPlugin): def __init__(self, log_file=None, verbose=False): self.log_file = log_file self.verbose = verbose
[docs] def setup(self, worker): LogUtil.configure(self.log_file, self.verbose)
@dask.delayed def delayed_log(logger, formated_log_msg, **kwargs): logger(formated_log_msg.format(**kwargs))