ATLAS Offline Software
Trigger/TriggerCommon/TriggerMenuMT/python/__init__.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon.Logging import logging, log
4 
5 class TriggerMenuMTFormatter(logging.Formatter):
6  """Custom formatter for loggers within TriggerMenuMT package.
7 
8  Logger names of type 'TriggerMenuMT.M1.M2.M3' will be shortened to
9  'TriggerMenuMT:M3' to avoid long logger names. Since the logging module
10  automatically applies log formats of parents to children this applies to
11  all loggers that are created via `logging.getLogger(__name__)` within
12  the TriggerMenuMT package.
13  """
14  def format(self, record):
15  fields = record.name.split('.')
16  if len(fields)>1:
17  record.name = ':'.join([fields[0], fields[-1]])
18  return super().format(record)
19 
20 
21 def _setupLogger(logger):
22  """Configure TriggerMenuMT logger"""
23  import copy
24  # Create custom handler/formatter but relying on athena defaults:
25  athena_hdlr = log.handlers[0]
26  hdlr = copy.copy(athena_hdlr)
27  hdlr.setFormatter(TriggerMenuMTFormatter(athena_hdlr.formatter._fmt))
28 
29  logger.propagate = False # avoid message duplication
30  logger.addHandler(hdlr)
31 
32 
33 # Create TriggerMenuMT root logger:
34 _log = logging.getLogger(__name__)
35 _setupLogger(_log)
36 _log.debug("Configuring TriggerMenuMT logger")
python._setupLogger
def _setupLogger(logger)
Definition: Trigger/TriggerCommon/TriggerMenuMT/python/__init__.py:21
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.TriggerMenuMTFormatter
Definition: Trigger/TriggerCommon/TriggerMenuMT/python/__init__.py:5
python.TriggerMenuMTFormatter.format
def format(self, record)
Definition: Trigger/TriggerCommon/TriggerMenuMT/python/__init__.py:14