Trying to weed out dual logging.
This commit is contained in:
parent
0e8bbb946d
commit
e0f1e1b5fd
|
|
@ -26,31 +26,40 @@ worker_history = oDict()
|
||||||
instructions = oDict()
|
instructions = oDict()
|
||||||
args = {}
|
args = {}
|
||||||
|
|
||||||
import logging
|
create_log = True
|
||||||
from systemd.journal import JournalHandler
|
|
||||||
|
|
||||||
# Custom adapter to pre-pend the 'origin' key.
|
try:
|
||||||
# TODO: Should probably use filters: https://docs.python.org/3/howto/logging-cookbook.html#using-filters-to-impart-contextual-information
|
if 'log' in __builtins__.__dict__:
|
||||||
class CustomAdapter(logging.LoggerAdapter):
|
create_log = False
|
||||||
|
except:
|
||||||
|
if 'log' in __builtins__:
|
||||||
|
create_log = False
|
||||||
|
|
||||||
|
if create_log:
|
||||||
|
import logging
|
||||||
|
from systemd.journal import JournalHandler
|
||||||
|
|
||||||
|
# Custom adapter to pre-pend the 'origin' key.
|
||||||
|
# TODO: Should probably use filters: https://docs.python.org/3/howto/logging-cookbook.html#using-filters-to-impart-contextual-information
|
||||||
|
class CustomAdapter(logging.LoggerAdapter):
|
||||||
def process(self, msg, kwargs):
|
def process(self, msg, kwargs):
|
||||||
return '[{}] {}'.format(self.extra['origin'], msg), kwargs
|
return '[{}] {}'.format(self.extra['origin'], msg), kwargs
|
||||||
|
|
||||||
logger = logging.getLogger() # __name__
|
logger = logging.getLogger() # __name__
|
||||||
journald_handler = JournalHandler()
|
journald_handler = JournalHandler()
|
||||||
journald_handler.setFormatter(logging.Formatter('[{levelname}] {message}', style='{'))
|
journald_handler.setFormatter(logging.Formatter('[{levelname}] {message}', style='{'))
|
||||||
logger.addHandler(journald_handler)
|
logger.addHandler(journald_handler)
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
class LOG_LEVELS:
|
class LOG_LEVELS:
|
||||||
CRITICAL = 1
|
CRITICAL = 1
|
||||||
ERROR = 2
|
ERROR = 2
|
||||||
WARNING = 3
|
WARNING = 3
|
||||||
INFO = 4
|
INFO = 4
|
||||||
DEBUG = 5
|
DEBUG = 5
|
||||||
|
|
||||||
LOG_LEVEL = 4
|
LOG_LEVEL = 4
|
||||||
|
def log(*msg, origin='UNKNOWN', level=5, **kwargs):
|
||||||
def log(*msg, origin='UNKNOWN', level=5, **kwargs):
|
|
||||||
if level <= LOG_LEVEL:
|
if level <= LOG_LEVEL:
|
||||||
msg = [item.decode('UTF-8', errors='backslashreplace') if type(item) == bytes else item for item in msg]
|
msg = [item.decode('UTF-8', errors='backslashreplace') if type(item) == bytes else item for item in msg]
|
||||||
msg = [str(item) if type(item) != str else item for item in msg]
|
msg = [str(item) if type(item) != str else item for item in msg]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue