Shubhasmit Gupta Shubhasmit Gupta - 25 days ago 5
Java Question

How to change testNG Reporter.log() encoding to UTF-16

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?

Answer

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