pytorch / ignite

High-level library to help with training and evaluating neural networks in PyTorch flexibly and transparently.
https://pytorch-ignite.ai
BSD 3-Clause "New" or "Revised" License
4.5k stars 608 forks source link

setup_logger: add optional arg `encoding` for FileHandler #3240

Closed sjiang95 closed 2 months ago

sjiang95 commented 2 months ago

By default, the encoding is utf-8 for compatibility with CJK characters.

Fixes #3239

Description:

Add an optional arg encoding to setup_logger(). By default, the encoding is utf-8 for compatibility with CJK characters.

Check list:

Test:

Can use the following script for test

from ignite.utils import setup_logger

utf8logger = setup_logger(name='utf8 logger', filepath='utf8.log')
utf8logger.info('你好')

logger = setup_logger(name='encoding is None', filepath='defaultEncode.log', encoding=None)
logger.info('你好')

In utf8.log

2024-04-23 17:53:23,792 utf8 logger INFO: 你好

while in defaultEncode.log

2024-04-23 17:53:23,792 encoding is None INFO: ���