diff --git a/pysegcnn/core/logging.py b/pysegcnn/core/logging.py index 4f42dc0535a83d6ff2e56c72abc7be273e588dc2..e8506c06b71012ce0642b837904ffff53a5daffb 100644 --- a/pysegcnn/core/logging.py +++ b/pysegcnn/core/logging.py @@ -4,11 +4,18 @@ Created on Fri Aug 14 10:07:12 2020 @author: Daniel """ +# builtins +import pathlib # the logging configuration dictionary def log_conf(logfile): + # check if the parent directory of the log file exists + logfile = pathlib.Path(logfile) + if not logfile.parent.is_dir(): + logfile.parents.mkdir(parent=True, exist_ok=True) + LOGGING_CONFIG = { 'version': 1, 'disable_existing_loggers': False, @@ -17,7 +24,8 @@ def log_conf(logfile): 'format': '%(name)s: %(message)s' }, 'standard': { - 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s' + 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s', + 'datefmt': '%Y-%m-%dT%H:%M:%S' }, }, 'handlers': { @@ -33,7 +41,7 @@ def log_conf(logfile): 'formatter': 'standard', 'level': 'INFO', 'filename': logfile, - 'mode': 'w' + 'mode': 'a' } }, 'loggers': {