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,
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
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(
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
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)
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):
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()