DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
opmonlib.utils.LoggingFormatter Class Reference
Inheritance diagram for opmonlib.utils.LoggingFormatter:
[legend]
Collaboration diagram for opmonlib.utils.LoggingFormatter:
[legend]

Public Member Functions

None __init__ (self, str fmt=full_log_format, str datefmt=date_time_format, tzinfo tz=time_zone)
 
str formatTime (self, logging.LogRecord record, str datefmt)
 
logging.LogRecord format (self, logging.LogRecord record)
 

Public Attributes

 tz = tz
 
 datefmt = datefmt
 

Detailed Description

Custom logging formatter for DUNE DAQ applications.

Definition at line 88 of file utils.py.

Constructor & Destructor Documentation

◆ __init__()

None opmonlib.utils.LoggingFormatter.__init__ ( self,
str fmt = full_log_format,
str datefmt = date_time_format,
tzinfo tz = time_zone )
Construct the logging formatter.

Definition at line 91 of file utils.py.

96 ) -> None:
97 """Construct the logging formatter."""
98 super().__init__(fmt, datefmt)
99 self.tz = tz
100 self.datefmt = datefmt
101

Member Function Documentation

◆ format()

logging.LogRecord opmonlib.utils.LoggingFormatter.format ( self,
logging.LogRecord record )
Apply the correct formatting to the log record.

Definition at line 107 of file utils.py.

107 def format(self, record: logging.LogRecord) -> logging.LogRecord:
108 """Apply the correct formatting to the log record."""
109 record.asctime = self.formatTime(record, self.datefmt)
110 # TODO: for production, remove filename and lineno entries
111 component_width = 30
112 file_lineno = f"{record.filename}:{record.lineno}"
113 record.filename = file_lineno.ljust(component_width)[:component_width]
114 component_width = 45
115 name_colon = f"{record.name}:"
116 if name_colon.startswith("drunc."):
117 name_colon = name_colon.replace("drunc.", "")
118 record.name = name_colon.ljust(component_width)[:component_width]
119 component_width = 10
120 level_name = record.levelname
121 record.levelname = level_name.ljust(component_width)[:component_width]
122 return super().format(record)
123
124

◆ formatTime()

str opmonlib.utils.LoggingFormatter.formatTime ( self,
logging.LogRecord record,
str datefmt )
Apply the correct formatting to the log record date and time.

Definition at line 102 of file utils.py.

102 def formatTime(self, record: logging.LogRecord, datefmt: str) -> str: # noqa: N802
103 """Apply the correct formatting to the log record date and time."""
104 date_time = datetime.fromtimestamp(record.created, self.tz)
105 return date_time.strftime(self.datefmt)
106

Member Data Documentation

◆ datefmt

opmonlib.utils.LoggingFormatter.datefmt = datefmt

Definition at line 100 of file utils.py.

◆ tz

opmonlib.utils.LoggingFormatter.tz = tz

Definition at line 99 of file utils.py.


The documentation for this class was generated from the following file: