summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <jbocklage-ryannel@luxoft.com>2018-01-18 15:09:57 +0100
committerJuergen Bocklage-Ryannel <jbocklage-ryannel@luxoft.com>2018-01-18 15:09:57 +0100
commit89e62a97b1d44bbb5e5d4e568d982b10846dfe2d (patch)
tree47310fe683e97f8a22980fcc5e7005228b4ed9c8
parent6e55cc3885ae54c08e71ae8736017adb5b38b759 (diff)
downloadqtivi-qface-89e62a97b1d44bbb5e5d4e568d982b10846dfe2d.tar.gz
added a log setup helper function
-rw-r--r--qface/contrib/__init__.py0
-rw-r--r--qface/contrib/logging.py28
2 files changed, 28 insertions, 0 deletions
diff --git a/qface/contrib/__init__.py b/qface/contrib/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/qface/contrib/__init__.py
diff --git a/qface/contrib/logging.py b/qface/contrib/logging.py
new file mode 100644
index 0000000..6b7625c
--- /dev/null
+++ b/qface/contrib/logging.py
@@ -0,0 +1,28 @@
+import yaml
+import logging
+import logging.config
+import coloredlogs
+from path import Path
+import os
+
+
+def basic_log(level):
+ logging.basicConfig(level=level)
+ coloredlogs.install(level=level)
+ print('Fall back to basic logging')
+
+
+def setup_log(path='logging.yaml', level=logging.INFO, env_key='QFACE_LOG_CFG'):
+ path = Path(os.getenv(env_key, path))
+ if path.exists():
+ try:
+ config = yaml.safe_load(path.text())
+ logging.config.dictConfig(config)
+ coloredlogs.install()
+ except Exception as e:
+ print(e)
+ print('Error in logging configuration. Fall back to defaults.')
+ basic_log(level)
+ else:
+ basic_log(level)
+ print('Failed to load logging config file.')