MCPcopy Create free account
hub / github.com/KoljaB/RealtimeVoiceChat / CustomTimeFormatter

Class CustomTimeFormatter

code/logsetup.py:7–36  ·  view source on GitHub ↗

A logging Formatter that displays timestamps as MM:SS.cs using local time. Inherits from `logging.Formatter` and overrides the `formatTime` method to provide a specific, concise timestamp format suitable for console output, using the local time zone derived from the log record's cr

Source from the content-addressed store, hash-verified

5
6# --- Define Custom Formatter to handle time locally ---
7class CustomTimeFormatter(logging.Formatter):
8 """
9 A logging Formatter that displays timestamps as MM:SS.cs using local time.
10
11 Inherits from `logging.Formatter` and overrides the `formatTime` method
12 to provide a specific, concise timestamp format suitable for console output,
13 using the local time zone derived from the log record's creation time.
14 """
15
16 def formatTime(self, record: logging.LogRecord, datefmt: Optional[str] = None) -> str:
17 """
18 Formats the log record's creation time into MM:SS.cs format.
19
20 Uses `time.localtime` to convert the record's creation timestamp and
21 formats it as minutes, seconds, and centiseconds. The `datefmt` argument
22 provided by the base class is ignored in this custom implementation.
23
24 Args:
25 record: The log record whose creation time needs formatting.
26 datefmt: An optional date format string (ignored by this method).
27
28 Returns:
29 A string representing the formatted time (e.g., "59:23.18").
30 """
31 # Use localtime as originally intended, but locally within this formatter
32 now = time.localtime(record.created)
33 cs = int((record.created % 1) * 100) # centiseconds
34 # Format the time string as required
35 s = time.strftime("%M:%S", now) + f".{cs:02d}"
36 return s
37
38def setup_logging(level: int = logging.INFO) -> None:
39 """

Callers 1

setup_loggingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected