Ahem. Still running black?
[python_utils.git] / logging_utils.py
index bf8d8b062b911507ccbd7f68f5346530c7bd0d79..2d9d63b78f8543890bb25fa879667bcc59294af1 100644 (file)
@@ -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()