MCPcopy Index your code
hub / github.com/su-kaka/gcli2api / _log

Function _log

log.py:228–251  ·  view source on GitHub ↗
(level: str, message: str)

Source from the content-addressed store, hash-verified

226# -----------------------------------------------------------------
227
228def _log(level: str, message: str):
229 # 最快短路:日志整体已禁用时直接返回,零开销
230 if not _log_enabled:
231 return
232
233 level = level.lower()
234 level_val = LOG_LEVELS.get(level)
235 if level_val is None:
236 print(f"Warning: Unknown log level '{level}'", file=sys.stderr)
237 return
238
239 # 热路径:直接与缓存值比较,无函数调用开销
240 if level_val < _cached_log_level:
241 return
242
243 timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
244 entry = f"[{timestamp}] [{level.upper()}] {message}"
245
246 if level in ("error", "critical"):
247 print(entry, file=sys.stderr)
248 else:
249 print(entry)
250
251 _write_to_file(entry)
252
253
254def set_log_level(level: str):

Callers 6

__call__Method · 0.85
debugMethod · 0.85
infoMethod · 0.85
warningMethod · 0.85
errorMethod · 0.85
criticalMethod · 0.85

Calls 1

_write_to_fileFunction · 0.85

Tested by

no test coverage detected