fix: RotatingFileHandler强制UTF-8编码避免Windows GBK日志乱码
This commit is contained in:
@@ -89,7 +89,8 @@ class LogService:
|
|||||||
runtime_handler = logging.handlers.RotatingFileHandler(
|
runtime_handler = logging.handlers.RotatingFileHandler(
|
||||||
self.log_dir / "runtime" / runtime_log_file,
|
self.log_dir / "runtime" / runtime_log_file,
|
||||||
maxBytes=self._parse_size(self.config['logging'].get('max_file_size', '10MB')),
|
maxBytes=self._parse_size(self.config['logging'].get('max_file_size', '10MB')),
|
||||||
backupCount=self.config['logging'].get('max_log_files', 3)
|
backupCount=self.config['logging'].get('max_log_files', 3),
|
||||||
|
encoding='utf-8'
|
||||||
)
|
)
|
||||||
runtime_handler.setLevel(getattr(logging, self.config['logging']['level'], logging.INFO))
|
runtime_handler.setLevel(getattr(logging, self.config['logging']['level'], logging.INFO))
|
||||||
runtime_handler.setFormatter(file_formatter)
|
runtime_handler.setFormatter(file_formatter)
|
||||||
@@ -101,7 +102,8 @@ class LogService:
|
|||||||
debug_handler = logging.handlers.RotatingFileHandler(
|
debug_handler = logging.handlers.RotatingFileHandler(
|
||||||
self.log_dir / "debug" / debug_log_file,
|
self.log_dir / "debug" / debug_log_file,
|
||||||
maxBytes=self._parse_size(self.config['logging'].get('max_file_size', '10MB')),
|
maxBytes=self._parse_size(self.config['logging'].get('max_file_size', '10MB')),
|
||||||
backupCount=self.config['logging'].get('max_log_files', 3)
|
backupCount=self.config['logging'].get('max_log_files', 3),
|
||||||
|
encoding='utf-8'
|
||||||
)
|
)
|
||||||
debug_handler.setLevel(logging.DEBUG)
|
debug_handler.setLevel(logging.DEBUG)
|
||||||
debug_handler.setFormatter(file_formatter)
|
debug_handler.setFormatter(file_formatter)
|
||||||
|
|||||||
Reference in New Issue
Block a user