diff options
| author | Scott <[email protected]> | 2022-01-06 12:13:34 -0800 |
|---|---|---|
| committer | Scott <[email protected]> | 2022-01-06 12:13:34 -0800 |
| commit | 5f75cf834725ac26b289cc5f157af0cb71cd5f0e (patch) | |
| tree | f31baf4247a7d29eb1457a74f75d373d10539237 /logging_utils.py | |
| parent | ba223f821df1e9b8abbb6f6d23d5ba92c5a70b05 (diff) | |
A bunch of changes...
Diffstat (limited to 'logging_utils.py')
| -rw-r--r-- | logging_utils.py | 28 |
1 files changed, 24 insertions, 4 deletions
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', @@ -87,6 +87,16 @@ cfg.add_argument( 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, default=False, @@ -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, |
