Logger creation unified, overwrite error method

This commit is contained in:
Lukas Klass 2020-05-29 09:33:43 +02:00
parent fb7c2b762d
commit 4a5d9cdc64

32
esbo_etc/lib/logger.py Normal file
View File

@ -0,0 +1,32 @@
import logging
import sys
import traceback
def error(self, msg: str, exit_: bool = True):
"""
Handle errors
Parameters
----------
self : Logger
The logger-object
msg : str
Error message to show
exit_ : bool
Exit program
Returns
-------
"""
self._error(msg)
if exit_:
traceback.print_stack()
sys.exit(1)
logging.basicConfig(level=logging.WARNING, format='%(levelname)s: %(message)s', stream=sys.stdout)
logger = logging.getLogger('etc')
logger._error = logger.error
logger.error = error.__get__(logger, logging.Logger)