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
@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))