Ran black code formatter on everything.
[python_utils.git] / logging_utils.py
index a15ccd64b24d9d3393fea65ab62ee2fcf27c348a..bf8d8b062b911507ccbd7f68f5346530c7bd0d79 100644 (file)
@@ -22,7 +22,9 @@ 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,
@@ -231,7 +233,9 @@ 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
@@ -440,8 +444,12 @@ 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(
@@ -525,7 +533,9 @@ 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
@@ -654,17 +664,23 @@ 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)
@@ -674,9 +690,13 @@ 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):
@@ -699,12 +719,18 @@ 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()
@@ -755,7 +781,10 @@ class OutputMultiplexerContext(OutputMultiplexer, contextlib.ContextDecorator):
         handles=None,
     ):
         super().__init__(
-            destination_bitv, logger=logger, filenames=filenames, handles=handles
+            destination_bitv,
+            logger=logger,
+            filenames=filenames,
+            handles=handles,
         )
 
     def __enter__(self):