how to configure my own formatter in java logging property file
Posted
by loudiyimo
on Stack Overflow
See other posts from Stack Overflow
or by loudiyimo
Published on 2010-04-26T00:25:50Z
Indexed on
2010/04/26
0:33 UTC
Read the original article
Hit count: 643
For my java project, i am using the java logging api. I want to log everything using a property file.
Before using this file (log.properties), I configured my onwn fommater in the java code. (see below)
Now I want to configure my own fomater in the propertie file, instead of the java code. does someone know how to do that ?
Formatter formatter = new Formatter() {
@Override
public String format(LogRecord arg0) {
StringBuilder b = new StringBuilder();
b.append(new Date());
b.append(" ");
b.append(arg0.getSourceClassName());
b.append(" ");
b.append(arg0.getSourceMethodName());
b.append(" ");
b.append(arg0.getLevel());
b.append(" ");
b.append(arg0.getMessage());
b.append(System.getProperty("line.separator"));
return b.toString();
}
};
fomatter in the java code
..... .....
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter java.util.logging.FileHandler.level=WARNING
java.util.logging.??? = how can i configure my own formater in the property files with this information: data, clasename, methodename, level .etc.**
formatter in de log.proprties
© Stack Overflow or respective owner