问题
I am using testNG with selenium. I have two kind of logger, one is log4j logger and the other is testNG Reporter.log(). Now the problem is I need to log some Chinese text. But it is coming as '????' instead of Chinese text. So I changed the log4j.properties file, just added two lines:
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.encoding=UTF-16
Now in my log4j logs it is coming properly but in testNG Reporter.log() it's still coming as '?????'.
Log4j log: Typed text '美联泰'
TestNG Reporter.log(): Typed text '???'
How to set testNG Reporter.log() encoding to UTF-16?
回答1:
Can you try Reporter#log(new String(s, "UTF-16"), level);
in the API?
See String API for details.
回答2:
I tried something else and now it's working. Just added JAVA_TOOL_OPTIONS
environment variable. Variable name: JAVA_TOOL_OPTIONS
Variable value: -Dfile.encoding=UTF8
来源:https://stackoverflow.com/questions/27013487/how-to-change-testng-reporter-log-encoding-to-utf-16