Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup_logger: add optional arg encoding for FileHandler #3240

Merged
merged 8 commits into from
May 8, 2024

Conversation

sjiang95
Copy link
Contributor

@sjiang95 sjiang95 commented Apr 23, 2024

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:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

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: ���

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

Signed-off-by: Shengjiang Quan <[email protected]>
@github-actions github-actions bot added the module: utils Utils module label Apr 23, 2024
@sjiang95 sjiang95 changed the title setup_logger: add optional arg encoding for FileHandler setup_logger: add optional arg encoding for FileHandler Apr 23, 2024
tests/ignite/test_utils.py Outdated Show resolved Hide resolved
tests/ignite/test_utils.py Outdated Show resolved Hide resolved
tests/ignite/test_utils.py Outdated Show resolved Hide resolved
@vfdev-5 vfdev-5 enabled auto-merge (squash) May 8, 2024 07:17
Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @sjiang95 !

@vfdev-5 vfdev-5 disabled auto-merge May 8, 2024 08:17
@vfdev-5 vfdev-5 merged commit 0c680df into pytorch:master May 8, 2024
15 of 20 checks passed
@sjiang95 sjiang95 deleted the logEncode branch May 10, 2024 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: utils Utils module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add optional arg encoding = None for ignite.utils.setup_logger
2 participants