Skip to content

Commit 00f4c44

Browse files
feat: windows logger utf8 error
1 parent cb7cbff commit 00f4c44

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

backend/utils/auth_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def extract_and_store_api_key(request) -> Optional[str]:
2929
# Verify it's stored correctly
3030
stored_key = get_comfyui_copilot_api_key()
3131
if stored_key == api_key:
32-
log.info("API key verification: Successfully stored in globals")
32+
log.info("API key verification: Successfully stored in globals")
3333
else:
34-
log.error("API key verification: Storage failed")
34+
log.error("API key verification: Storage failed")
3535

3636
return api_key
3737
else:

backend/utils/logger.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import inspect
1010
from datetime import datetime
11+
import io
1112

1213

1314
class LocationFormatter(logging.Formatter):
@@ -35,8 +36,22 @@ def setup_logger():
3536
if logger.handlers:
3637
return logger
3738

38-
# Console handler with color support
39-
console_handler = logging.StreamHandler(sys.stderr)
39+
# Console handler with safer encoding handling on Windows consoles
40+
# Prefer reconfiguring the existing stderr to replace unencodable chars
41+
if hasattr(sys.stderr, "reconfigure"):
42+
try:
43+
sys.stderr.reconfigure(errors="replace")
44+
except Exception:
45+
pass
46+
console_handler = logging.StreamHandler(sys.stderr)
47+
else:
48+
# Fallback: wrap the underlying buffer with a TextIOWrapper that replaces errors
49+
try:
50+
encoding = getattr(sys.stderr, "encoding", None) or "utf-8"
51+
console_stream = io.TextIOWrapper(sys.stderr.buffer, encoding=encoding, errors="replace")
52+
console_handler = logging.StreamHandler(console_stream)
53+
except Exception:
54+
console_handler = logging.StreamHandler(sys.stderr)
4055
console_handler.setLevel(logging.DEBUG)
4156

4257
# Console formatter with colors (simple format for better compatibility)
@@ -51,7 +66,8 @@ def setup_logger():
5166
file_handler = logging.handlers.RotatingFileHandler(
5267
os.path.join(log_dir, "comfyui_copilot.log"),
5368
maxBytes=10*1024*1024, # 10MB
54-
backupCount=7
69+
backupCount=7,
70+
encoding='utf-8'
5571
)
5672
file_handler.setLevel(logging.DEBUG)
5773

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "ComfyUI-Copilot"
33
description = "Your Intelligent Assistant for Comfy-UI."
4-
version = "2.0.20"
4+
version = "2.0.21"
55
license = {file = "LICENSE"}
66

77
[project.urls]

0 commit comments

Comments
 (0)