You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by KUROSAKA Teruhiko <ku...@bhlab.com> on 2003/10/30 08:36:16 UTC
How do I set the character encoding ?
Hello,
I am new to the list, and to log4j.
It seems that log4j writes log in the encoding specified
by file.encoding property. Is there a way to override this?
I would like to write my log files in UTF-8 encoding
regardless of the platform's locale setting.
Experimenting with Sort.java sample program, I thought
this would work:
static Logger logger = Logger.getLogger(Sort.class.getName());
....
Enumeration appenders=logger.getAllAppenders();
if(appenders!=null){
if(!appenders.hasMoreElements()){
System.out.println("getAllAppender() returned zero-count
Enuml.\n");
}else{
while(appenders.hasMoreElements()){
Object o=appenders.nextElement();
if (o instanceof WriterAppender){
((WriterAppender)o).setEncoding("UTF-8");
System.out.println("setEncoding called.\n");
}
}
}
}else{
System.out.println("getAllAppender() returned null.\n");
}
But it doesn't because getAllAppenders() returns the NullEnumerator.
I am actually hoping that this can be done in configuration, like:
log4j.appender.R.encoding=UTF-8
Is there such luck ?
KUROSAKA "Kuro" Teruhiko
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org