MCPcopy Create free account
hub / github.com/su-kaka/gcli2api / _open_log_file

Function _open_log_file

log.py:74–89  ·  view source on GitHub ↗
(mode: str = "a")

Source from the content-addressed store, hash-verified

72
73
74def _open_log_file(mode: str = "a") -> bool:
75 global _log_file_handle, _file_writing_disabled, _disable_reason
76 _close_log_file()
77 try:
78 # 使用较大缓冲区(64 KB),由 writer 线程定期 flush,减少系统调用
79 _log_file_handle = open(_cached_log_file, mode, encoding="utf-8", buffering=65536)
80 return True
81 except (PermissionError, OSError, IOError) as e:
82 _file_writing_disabled = True
83 _disable_reason = str(e)
84 print(f"Warning: Cannot open log file, disabling file writing: {e}", file=sys.stderr)
85 print("Log messages will continue to display in console only.", file=sys.stderr)
86 return False
87 except Exception as e:
88 print(f"Warning: Failed to open log file: {e}", file=sys.stderr)
89 return False
90
91
92def _clear_log_file():

Callers 2

_clear_log_fileFunction · 0.85
_log_writer_workerFunction · 0.85

Calls 1

_close_log_fileFunction · 0.85

Tested by

no test coverage detected