| 65 | class="st">""" |
| 66 | |
| 67 | def formatTime(self, record: LogRecord, datefmt: str | None = None) -> str: |
| 68 | if datefmt and class="st">"%f" in datefmt: |
| 69 | ct = self.converter(record.created) |
| 70 | tz = timezone(timedelta(seconds=ct.tm_gmtoff), ct.tm_zone) |
| 71 | class="cm"># Construct `datetime.datetime` object from `struct_time` |
| 72 | class="cm"># and msecs information from `record` |
| 73 | class="cm"># Using int() instead of round() to avoid it exceeding 1_000_000 and causing a ValueError (#11861). |
| 74 | dt = datetime(*ct[0:6], microsecond=int(record.msecs * 1000), tzinfo=tz) |
| 75 | return dt.strftime(datefmt) |
| 76 | class="cm"># Use `logging.Formatter` for non-microsecond formats |
| 77 | return super().formatTime(record, datefmt) |
| 78 | |
| 79 | |
| 80 | class ColoredLevelFormatter(DatetimeFormatter): |