我在log4j日志中面临很多问题.. 每当我停止在Weblogic控制台上构建并恢复它时,它会生成双重日志。 这是日志:
[21 Jul 2014 11:03:30,053] INFO [T006] - Creating connection to [127.0.0.1:6582]
[21 Jul 2014 11:03:30,054] INFO [T006] - Connection established [127.0.0.1:6582]
[21 Jul 2014 11:03:30,054] INFO [T006] - Creating connection to [127.0.0.1:6583]
[21 Jul 2014 11:03:30,055] INFO [T006] - Connection established [127.0.0.1:6583]
[21 Jul 2014 11:03:30,055] INFO [T006] - Creating connection to [127.0.0.1:6584]
[21 Jul 2014 11:03:30,055] INFO [T006] - Connection established [127.0.0.1:6584]
[21 Jul 2014 11:03:30,950] INFO [T006] - Response Q connected...
[21 Jul 2014 11:03:30,975] INFO [T006] - Request Queue Connected.
[21 Jul 2014 11:03:30,980] INFO [T006] - Message Timeout Monitor is Started for T006
[21 Jul 2014 11:04:28,736] INFO [T006] - Destroying messageTimeoutMonitor Thread.
[21 Jul 2014 11:04:28,736] INFO [T006] - Destroying keepAlive Thread.
[21 Jul 2014 11:04:28,736] INFO [T006] - Receiver Thread Shutdown on port 6582
[21 Jul 2014 11:04:28,737] INFO [T006] - Receiver Thread Shutdown on port 6583
[21 Jul 2014 11:04:28,737] INFO [T006] - Receiver Thread Shutdown on port 6584
[21 Jul 2014 11:05:08,898] INFO [T006] - Creating connection to [127.0.0.1:6582]
[21 Jul 2014 11:05:08,898] INFO [T006] - Creating connection to [127.0.0.1:6582]
[21 Jul 2014 11:05:08,898] INFO [T006] - Connection established [127.0.0.1:6582]
[21 Jul 2014 11:05:08,898] INFO [T006] - Connection established [127.0.0.1:6582]
[21 Jul 2014 11:05:08,899] INFO [T006] - Creating connection to [127.0.0.1:6583]
[21 Jul 2014 11:05:08,899] INFO [T006] - Creating connection to [127.0.0.1:6583]
[21 Jul 2014 11:05:08,899] INFO [T006] - Connection established [127.0.0.1:6583]
[21 Jul 2014 11:05:08,899] INFO [T006] - Connection established [127.0.0.1:6583]
[21 Jul 2014 11:05:08,899] INFO [T006] - Creating connection to [127.0.0.1:6584]
[21 Jul 2014 11:05:08,899] INFO [T006] - Creating connection to [127.0.0.1:6584]
[21 Jul 2014 11:05:08,899] INFO [T006] - Connection established [127.0.0.1:6584]
[21 Jul 2014 11:05:08,899] INFO [T006] - Connection established [127.0.0.1:6584]
[21 Jul 2014 11:05:08,911] INFO [T006] - Response Q connected...
[21 Jul 2014 11:05:08,911] INFO [T006] - Response Q connected...
[21 Jul 2014 11:05:08,917] INFO [T006] - Request Queue Connected.
[21 Jul 2014 11:05:08,917] INFO [T006] - Request Queue Connected.
[21 Jul 2014 11:05:08,924] INFO [T006] - Message Timeout Monitor is Started for T006
[21 Jul 2014 11:05:08,924] INFO [T006] - Message Timeout Monitor is Started for T006
我没有用XML编写log4j配置。我已经完成了代码。 解决方案是什么?
这是守则: Log4jConfiguration类 公共类Log4jConfigurationBean { private String logLevel; 私有String路径; private String fileName; private String errorFileName; private String applicationName;
public Level getLogLevel() {
Level level = null;
if(logLevel=="debug")
level = Level.DEBUG;
else if(logLevel.equalsIgnoreCase("all"))
level = Level.ALL;
else if(logLevel.equalsIgnoreCase("warn"))
level = Level.WARN;
else if(logLevel.equalsIgnoreCase("info"))
level = Level.INFO;
else if(logLevel.equalsIgnoreCase("error"))
level = Level.ERROR;
else if(logLevel.equalsIgnoreCase("debug"))
level = Level.DEBUG;
else if(logLevel.equalsIgnoreCase("trace"))
level = Level.TRACE;
return level;
}
套接字记录器类 公共类SocketLogger {
private static SingletonStaticContainer singletonStaticContainer = SingletonStaticContainer.getInstance();
public void configureLogger(Log4jConfigurationBean log4jConfiguration){
PatternLayout otherLayout = new PatternLayout(
"[%d{DATE}] %-5p ["+log4jConfiguration.getApplicationName()+"] %x - %m%n"
);
PatternLayout errorLayout = new PatternLayout(
//"[%d{DATE}] %-5p %l ["+log4jConfiguration.getApplicationName()+"] %x - %m%n"
"[%d{DATE}] %-5p ["+log4jConfiguration.getApplicationName()+"] %x - %m%n"
);
//remove console laout not using anymore
//rootLogger.addAppender(new ConsoleAppender(otherLayout));
try {
//creating error file appender
RollingFileAppender errorAppender = new RollingFileAppender(errorLayout,log4jConfiguration.getPath()+log4jConfiguration.getErrorFileName());
errorAppender.setMaxFileSize("200MB");
errorAppender.activateOptions();
errorAppender.addFilter(new ErrorFilter());
//creating fileappender for other then error messages
RollingFileAppender fileAppender = new RollingFileAppender(otherLayout,log4jConfiguration.getPath()+log4jConfiguration.getFileName());
fileAppender.setMaxFileSize("200MB");
fileAppender.activateOptions();
fileAppender.addFilter(new CustomFilter());
Logger rootLogger = Logger.getLogger(singletonStaticContainer.getInstance().applicationName);
rootLogger.setLevel(log4jConfiguration.getLogLevel());
rootLogger.addAppender(errorAppender);
rootLogger.addAppender(fileAppender);
Logger.getLogger(singletonStaticContainer.applicationName);
Logger rootLogger = Logger.getLogger(SocketLogger.class);
rootLogger.setLevel(log4jConfiguration.getLogLevel());
rootLogger.addAppender(errorAppender);
rootLogger.addAppender(fileAppender);*/
//remove console laout not using anymore
//rootLogger.addAppender(new ConsoleAppender(otherLayout));
} catch (IOException e) {
e.printStackTrace();
}
}
}