mscp.classes.loguruformatter
Custom log formatting for loguru.
Provides LoguruFormatter, which produces a fixed-width log line by padding
the name:function:line block to the longest value seen so far.
Classes
Section titled “Classes”LoguruFormatter
Section titled “LoguruFormatter”class LoguruFormatter(BaseModel)Format loguru records with a self-widening location column.
Each call to format_log measures the length of
"{name}:{function}:{line}" for the current record and grows padding
to the widest value seen so far, so columns line up across log lines
without truncating any of them.
Attributes
padding(int) — Largestname:function:linewidth observed, used to right-pad shorter values. Starts at 0 and grows monotonically.log_format(str) — Theloguruformat string applied to each record. Includes{extra[padding]}so the padding spaces populated byformat_logare inserted at format time.
Methods
Section titled “Methods”format_log
Section titled “format_log”format_log(self, record) -> strCompute the padding for record and return the format string.
Updates self.padding to the maximum of its current value and the
width of the record’s name:function:line, then writes the
difference into record["extra"]["padding"] so it can be
interpolated into log_format.
Args
record(dict) — Thelogururecord being formatted. Must containname,function,line, and anextradict;extra["padding"]is set as a side effect.
Returns
str— The format string inlog_format, ready forloguruto render with the now-populated record.