You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Win32下配置Log::Log4perl:文件输出UTF-8,屏幕输出CP866

Configuring Log::Log4perl for UTF-8 File Output and CP866 Console Output on Win32

To set up separate encodings for your file and screen appenders on Windows, you just need to add the encoding parameter to each appender's configuration block. Here's the complete, adjusted config:

log4perl.logger.bc_log = INFO, bc_log, console

# File appender with UTF-8 encoding
log4perl.appender.bc_log = Log::Log4perl::Appender::File
log4perl.appender.bc_log.filename = bc.log
log4perl.appender.bc_log.encoding = utf-8
log4perl.appender.bc_log.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.bc_log.layout.ConversionPattern = %d{ISO8601}%d{Z} %H %m%n

# Console appender with CP866 encoding (stderr)
log4perl.appender.console = Log::Log4perl::Appender::Screen
log4perl.appender.console.stderr = 1
log4perl.appender.console.encoding = cp866
log4perl.appender.console.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.console.layout.ConversionPattern = %d{ISO8601}%d{Z} %H %m%n

Key Changes Explained:

  • File Appender: The encoding = utf-8 line ensures the bc.log file is written using UTF-8 encoding, preserving all characters correctly regardless of the system's default code page.
  • Console Appender: The encoding = cp866 line forces stderr output to use CP866, the standard code page for Cyrillic characters in Windows consoles, preventing garbled text in your terminal.

Note: Ensure you're using Log::Log4perl v1.30 or later—this version introduced full encoding support for both File and Screen appenders. You can check your module version with:

perl -MLog::Log4perl -e 'print $Log::Log4perl::VERSION'

内容的提问来源于stack exchange,提问作者gapsf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:17:08