From 6020d5b3b2fa6f0f4fa761d8e31cf68ec26e904d Mon Sep 17 00:00:00 2001
From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu>
Date: Mon, 17 Aug 2020 17:21:44 +0200
Subject: [PATCH] Improved logging configuration function: path check and
 dateformat added

---
 pysegcnn/core/logging.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/pysegcnn/core/logging.py b/pysegcnn/core/logging.py
index 4f42dc0..e8506c0 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': {
-- 
GitLab