diff options
| author | Scott <[email protected]> | 2022-01-26 21:35:20 -0800 |
|---|---|---|
| committer | Scott <[email protected]> | 2022-01-26 21:35:20 -0800 |
| commit | e6f32fdd9b373dfcd100c7accb41f57d83c2f0a1 (patch) | |
| tree | eea4985bc43238fbd070c783441f08988f581973 /logging_utils.py | |
| parent | 36fea7f15ed17150691b5b3ead75450e575229ef (diff) | |
Ahem. Still running black?
Diffstat (limited to 'logging_utils.py')
| -rw-r--r-- | logging_utils.py | 50 |
1 files changed, 12 insertions, 38 deletions
diff --git a/logging_utils.py b/logging_utils.py index bf8d8b0..2d9d63b 100644 --- a/logging_utils.py +++ b/logging_utils.py @@ -22,9 +22,7 @@ import pytz import argparse_utils import config -cfg = config.add_commandline_args( - f'Logging ({__file__})', 'Args related to logging' -) +cfg = config.add_commandline_args(f'Logging ({__file__})', 'Args related to logging') cfg.add_argument( '--logging_config_file', type=argparse_utils.valid_filename, @@ -233,9 +231,7 @@ class SquelchRepeatedMessagesFilter(logging.Filter): if id1 not in squelched_logging_counts: return True threshold = squelched_logging_counts[id1] - logsite = ( - f'{record.pathname}+{record.lineno}+{record.levelno}+{record.msg}' - ) + logsite = f'{record.pathname}+{record.lineno}+{record.levelno}+{record.msg}' count = self.counters[logsite] self.counters[logsite] += 1 return count < threshold @@ -444,12 +440,8 @@ def initialize_logging(logger=None) -> logging.Logger: if config.config['logging_syslog']: if sys.platform not in ('win32', 'cygwin'): if config.config['logging_syslog_facility']: - facility_name = ( - 'LOG_' + config.config['logging_syslog_facility'] - ) - facility = SysLogHandler.__dict__.get( - facility_name, SysLogHandler.LOG_USER - ) + facility_name = 'LOG_' + config.config['logging_syslog_facility'] + facility = SysLogHandler.__dict__.get(facility_name, SysLogHandler.LOG_USER) handler = SysLogHandler(facility=facility, address='/dev/log') handler.setFormatter( MillisecondAwareFormatter( @@ -533,9 +525,7 @@ def initialize_logging(logger=None) -> logging.Logger: level_name = logging._levelToName.get( default_logging_level, str(default_logging_level) ) - logger.debug( - f'Initialized global logging; default logging level is {level_name}.' - ) + logger.debug(f'Initialized global logging; default logging level is {level_name}.') if ( config.config['logging_clear_preexisting_handlers'] and preexisting_handlers_count > 0 @@ -664,23 +654,17 @@ class OutputMultiplexer(object): self.logger = logger if filenames is not None: - self.f = [ - open(filename, 'wb', buffering=0) for filename in filenames - ] + self.f = [open(filename, 'wb', buffering=0) for filename in filenames] else: if destination_bitv & OutputMultiplexer.FILENAMES: - raise ValueError( - "Filenames argument is required if bitv & FILENAMES" - ) + raise ValueError("Filenames argument is required if bitv & FILENAMES") self.f = None if handles is not None: self.h = [handle for handle in handles] else: if destination_bitv & OutputMultiplexer.Destination.FILEHANDLES: - raise ValueError( - "Handle argument is required if bitv & FILEHANDLES" - ) + raise ValueError("Handle argument is required if bitv & FILEHANDLES") self.h = None self.set_destination_bitv(destination_bitv) @@ -690,13 +674,9 @@ class OutputMultiplexer(object): def set_destination_bitv(self, destination_bitv: int): if destination_bitv & self.Destination.FILENAMES and self.f is None: - raise ValueError( - "Filename argument is required if bitv & FILENAMES" - ) + raise ValueError("Filename argument is required if bitv & FILENAMES") if destination_bitv & self.Destination.FILEHANDLES and self.h is None: - raise ValueError( - "Handle argument is required if bitv & FILEHANDLES" - ) + raise ValueError("Handle argument is required if bitv & FILEHANDLES") self.destination_bitv = destination_bitv def print(self, *args, **kwargs): @@ -719,18 +699,12 @@ class OutputMultiplexer(object): end = "\n" if end == '\n': buf += '\n' - if ( - self.destination_bitv & self.Destination.FILENAMES - and self.f is not None - ): + if self.destination_bitv & self.Destination.FILENAMES and self.f is not None: for _ in self.f: _.write(buf.encode('utf-8')) _.flush() - if ( - self.destination_bitv & self.Destination.FILEHANDLES - and self.h is not None - ): + if self.destination_bitv & self.Destination.FILEHANDLES and self.h is not None: for _ in self.h: _.write(buf) _.flush() |
