created logging initializer

This commit is contained in:
vky 2022-01-30 00:00:56 +01:00
parent 72dee6dac7
commit 3cd6c5ed12
1 changed files with 19 additions and 0 deletions

View File

@ -1 +1,20 @@
# Dedicated module for defining and interpreting errors as well as generating error messages
import logging
logging.basicConfig(encoding='utf-8', level=logging.DEBUG)
def initlogging(filename=None, loglevel="ERROR"):
"""
Initializes logging
"""
loglevel = loglevel.upper()
if loglevel not in ["ERROR", "INFO", "WARNING", "DEBUG", "CRITICAL"]:
print("Incorrect logging", loglevel + ". Defaulting to ERROR.")
loglevel = "ERROR"
logging.basicConfig(encoding="utf-8")
if filename is not None:
logging.basicConfig(filename=filename)
logging.basicConfig(level=logging.__getattribute__(loglevel))