Trying to weed out dual logging.
This commit is contained in:
parent
0e8bbb946d
commit
e0f1e1b5fd
|
|
@ -26,31 +26,40 @@ worker_history = oDict()
|
|||
instructions = oDict()
|
||||
args = {}
|
||||
|
||||
import logging
|
||||
from systemd.journal import JournalHandler
|
||||
create_log = True
|
||||
|
||||
# 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):
|
||||
try:
|
||||
if 'log' in __builtins__.__dict__:
|
||||
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):
|
||||
return '[{}] {}'.format(self.extra['origin'], msg), kwargs
|
||||
|
||||
logger = logging.getLogger() # __name__
|
||||
journald_handler = JournalHandler()
|
||||
journald_handler.setFormatter(logging.Formatter('[{levelname}] {message}', style='{'))
|
||||
logger.addHandler(journald_handler)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger = logging.getLogger() # __name__
|
||||
journald_handler = JournalHandler()
|
||||
journald_handler.setFormatter(logging.Formatter('[{levelname}] {message}', style='{'))
|
||||
logger.addHandler(journald_handler)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
class LOG_LEVELS:
|
||||
class LOG_LEVELS:
|
||||
CRITICAL = 1
|
||||
ERROR = 2
|
||||
WARNING = 3
|
||||
INFO = 4
|
||||
DEBUG = 5
|
||||
|
||||
LOG_LEVEL = 4
|
||||
|
||||
def log(*msg, origin='UNKNOWN', level=5, **kwargs):
|
||||
LOG_LEVEL = 4
|
||||
def log(*msg, origin='UNKNOWN', level=5, **kwargs):
|
||||
if level <= LOG_LEVEL:
|
||||
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]
|
||||
|
|
|
|||
Loading…
Reference in New Issue