-
-
Notifications
You must be signed in to change notification settings - Fork 623
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
Add optional arg encoding = None
for ignite.utils.setup_logger
#3239
Comments
Thanks for the suggestion of improvement, @sjiang95 ! Few notes in case you would like to send a PR:
def setup_logger(
name: Optional[str] = "ignite",
level: int = logging.INFO,
stream: Optional[TextIO] = None,
format: str = "%(asctime)s %(name)s %(levelname)s: %(message)s",
filepath: Optional[str] = None,
distributed_rank: Optional[int] = None,
reset: bool = False,
encoding: Optional[str] = None, # add this optional arg
) -> logging.Logger:
|
Hello @vfdev-5 , thanks for your response. I also want to set |
@sjiang95 by the way, what is your OS, windows ? By default, logging FileHandler is using default encoding as in
Source: https://docs.python.org/3/library/functions.html#open and
Testing on the linux your PR, even with encoding=None we have already utf-8 encoding: fp = dirname / "log"
logger = setup_logger(name="logger", filepath=fp, encoding=None)
logger.info("你好") # ni hao
with open(fp, "r") as h:
data = h.readlines()
assert "你好" in data[0] so, your PR will fix this for other OS and setups... |
@vfdev-5 yes I encountered this problem on windows. How do you think we should deal with this? How about importing |
We can use encoding="utf-8" by default and in the tests check the platform as you are suggesting. |
🚀 Feature
Add optional arg
encoding = None
forignite.utils.setup_logger
Motivation
I encountered garbled text when loggering messages that contains CJK characters using
logger.info()
. For example,In the .log file, garbled text is printed.
Solution
This can be addressed by simply passing
encoding = "utf-8"
to the filehandlerignite/ignite/utils.py
Line 268 in f431e60
Looking forward to a discussion about this before I create a PR.
The text was updated successfully, but these errors were encountered: