Skip to content
Snippets Groups Projects
Commit 6020d5b3 authored by Frisinghelli Daniel's avatar Frisinghelli Daniel
Browse files

Improved logging configuration function: path check and dateformat added

parent 3f14aa4c
No related branches found
No related tags found
No related merge requests found
......@@ -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': {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment