MCPcopy Create free account
hub / github.com/dbunt1tled/python-fast-api / LokiJSONFormatter

Class LokiJSONFormatter

src/core/log/formatter/loki.py:9–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8
9class LokiJSONFormatter(logging.Formatter):
10 def format(self, record):
11 log_data = {
12 "timestamp": Colors.GREEN
13 + datetime.fromtimestamp(record.created, tz=ZoneInfo("Europe/Kyiv")).strftime("%Y-%m-%d %H:%M:%S")
14 + "(Kyiv)"
15 + Colors.RESET,
16 "level": Colors.LEVEL_COLORS.get(record.levelname, record.levelname),
17 "logger": record.name,
18 "message": record.getMessage(),
19 }
20
21 if hasattr(record, "extra_data") and record.extra_data:
22 for key, value in record.extra_data.items():
23 if isinstance(value, str) and key not in ["timestamp", "level", "logger", "message"]:
24 log_data[key] = Colors.colorize_value(value)
25 else:
26 log_data[key] = value
27
28 return json.dumps(log_data, ensure_ascii=False, default=str)

Callers 1

setupMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected