From 5f75cf834725ac26b289cc5f157af0cb71cd5f0e Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 6 Jan 2022 12:13:34 -0800 Subject: A bunch of changes... --- logging_utils.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'logging_utils.py') diff --git a/logging_utils.py b/logging_utils.py index 819e3d3..278cbf0 100644 --- a/logging_utils.py +++ b/logging_utils.py @@ -43,8 +43,8 @@ cfg.add_argument( cfg.add_argument( '--logging_format', type=str, - default='%(levelname).1s:%(asctime)s: %(message)s', - help='The format for lines logged via the logger module.' + default=None, + help='The format for lines logged via the logger module. See: https://docs.python.org/3/library/logging.html#formatter-objects' ) cfg.add_argument( '--logging_date_format', @@ -86,6 +86,16 @@ cfg.add_argument( default=False, help='Should we log to localhost\'s syslog.' ) +cfg.add_argument( + '--logging_syslog_facility', + type=str, + default = 'USER', + choices=['NOTSET', 'AUTH', 'AUTH_PRIV', 'CRON', 'DAEMON', 'FTP', 'KERN', 'LPR', 'MAIL', 'NEWS', + 'SYSLOG', 'USER', 'UUCP', 'LOCAL0', 'LOCAL1', 'LOCAL2', 'LOCAL3', 'LOCAL4', 'LOCAL5', + 'LOCAL6', 'LOCAL7'], + metavar='SYSLOG_FACILITY_LIST', + help='The default syslog message facility identifier', +) cfg.add_argument( '--logging_debug_threads', action=argparse_utils.ActionNoYes, @@ -382,7 +392,14 @@ def initialize_logging(logger=None) -> logging.Logger: if not isinstance(default_logging_level, int): raise ValueError('Invalid level: %s' % config.config['logging_level']) - fmt = config.config['logging_format'] + if config.config['logging_format']: + fmt = config.config['logging_format'] + else: + if config.config['logging_syslog']: + fmt = '%(levelname).1s:%(filename)s[%(process)d]: %(message)s' + else: + fmt = '%(levelname).1s:%(asctime)s: %(message)s' + if config.config['logging_debug_threads']: fmt = f'%(process)d.%(thread)d|{fmt}' if config.config['logging_debug_modules']: @@ -390,7 +407,10 @@ def initialize_logging(logger=None) -> logging.Logger: if config.config['logging_syslog']: if sys.platform not in ('win32', 'cygwin'): - handler = SysLogHandler() + if config.config['logging_syslog_facility']: + facility_name = 'LOG_' + config.config['logging_syslog_facility'] + facility = SysLogHandler.__dict__.get(facility_name, SysLogHandler.LOG_USER) + handler = SysLogHandler(facility=SysLogHandler.LOG_CRON, address='/dev/log') handler.setFormatter( MillisecondAwareFormatter( fmt=fmt, -- cgit v1.3