I have multithreaded application and i want add some text information in every log message I create factory and extend class, it works fine
...
protected Logger logger = Logger.getLogger("Test", new MyLog4JFactory());
...
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
public class MyLog4JFactory implements LoggerFactory{
@Override
public Logger makeNewLoggerInstance(String arg0) {
return new MyLogger(arg0);
}
}
import org.apache.log4j.Logger;
public class MyLogger extends Logger{
protected MyLogger(String name) {
super(name);
}
private String getMessage(Object msg){
StringBuffer sb = new StringBuffer();
return sb.append(msg).append(" ").append("My text").toString();
}
@Override
public void debug(Object message) {
super.debug(getMessage(message));
}
@Override
public void error(Object message) {
super.error(getMessage(message));
}
@Override
public void fatal(Object message) {
super.fatal(getMessage(message));
}
@Override
public void info(Object message) {
super.info(getMessage(message));
}
@Override
public void warn(Object message) {
super.warn(getMessage(message));
}
}
但愿 标识一见包装类别
a. 所有日志
2011-09-08 10:45:49,359德国马克 (35) - 测试1 我的案文
我对记录档案应该做些什么来显示(有线号)有人叫我的记录。