MCPcopy Create free account
hub / github.com/THESIS-AGENT/AIRouter / format

Method format

ew_config/logging_config.py:68–90  ·  view source on GitHub ↗
(self, record)

Source from the content-addressed store, hash-verified

66 """结构化日志格式化器,输出JSON格式"""
67
68 def format(self, record):
69 log_obj = {
70 'timestamp': datetime.fromtimestamp(record.created).isoformat(),
71 'level': record.levelname,
72 'logger': record.name,
73 'message': record.getMessage(),
74 'function': record.funcName,
75 'line': record.lineno
76 }
77
78 # 添加额外的上下文信息
79 if hasattr(record, 'source'):
80 log_obj['source'] = record.source
81 if hasattr(record, 'model'):
82 log_obj['model'] = record.model
83 if hasattr(record, 'api_type'):
84 log_obj['api_type'] = record.api_type
85 if hasattr(record, 'error_type'):
86 log_obj['error_type'] = record.error_type
87 if hasattr(record, 'execution_time'):
88 log_obj['execution_time'] = record.execution_time
89
90 return json.dumps(log_obj, ensure_ascii=False)
91
92
93def setup_optimized_logging(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected