aboutsummaryrefslogtreecommitdiffstats
path: root/netmodel/util/log.py
diff options
context:
space:
mode:
Diffstat (limited to 'netmodel/util/log.py')
-rw-r--r--netmodel/util/log.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/netmodel/util/log.py b/netmodel/util/log.py
index 68eb9a7f..f9fa1e03 100644
--- a/netmodel/util/log.py
+++ b/netmodel/util/log.py
@@ -21,6 +21,17 @@ import logging.config
import os
import sys
+from netmodel.util.file import ensure_writable_directory
+
+# Monkey-patch logging.FileHandler to support expanduser()
+oldFileHandler = logging.FileHandler
+class vICNFileHandler(oldFileHandler):
+ def __init__(self, filename, mode='a', encoding=None, delay=False):
+ filename = os.path.expanduser(filename)
+ ensure_writable_directory(os.path.dirname(filename))
+ super().__init__(filename, mode, encoding, delay)
+logging.FileHandler = vICNFileHandler
+
colors = {
'white': "\033[1;37m",
'yellow': "\033[1;33m",
@@ -107,6 +118,7 @@ def initialize_logging():
if os.path.exists(config_path):
logging.config.fileConfig(config_path, disable_existing_loggers=False)
+
root = logging.getLogger()
root.setLevel(logging.DEBUG)