Details
Description
OS: Windows
Software platform: j2ee, spring, webservices, junit, log4j2
I want to make sure that the failover configuration works as expected.
I configured failover appender with two rolling file appenders. Primary rolling file appender configured to a shared folder in different computer. Secondary file appender pointing to my local file system. Once after i ran the junit program and the first debug statement printed, i removed the share location from the other computer in the network for the primary appender. As expected next debug statements ( i left thread.sleep(30000) in between each debug statement in junit program) were redirect to secondary file appender. However at the time of retry by failover appender , it tries to reconnect to the primary location which is up now (enabled the share location in different computer), but received following error..
2014-10-21 10:34:11,463 ERROR Unable to write to stream //L-Computer1/test/logs/primary.log for appender primeCompressedDaily 2014-10-21 10:34:11,463 ERROR An exception occurred processing Appender primeCompressedDaily org.apache.logging.log4j.core.appender.AppenderLoggingException: Error flushing stream //L-Computer1/test/logs/primary.log at org.apache.logging.log4j.core.appender.OutputStreamManager.flush(OutputStreamManager.java:159) at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:108) at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:86) at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:97) at org.apache.logging.log4j.core.appender.FailoverAppender.callAppender(FailoverAppender.java:117) at org.apache.logging.log4j.core.appender.FailoverAppender.append(FailoverAppender.java:109) at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:97) at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.callAppenders(AsyncAppender.java:288) at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.run(AsyncAppender.java:240) Caused by: java.io.IOException: The specified network name is no longer available at java.io.FileOutputStream.writeBytes(Native Method) at java.io.FileOutputStream.write(FileOutputStream.java:318) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) at org.apache.logging.log4j.core.appender.OutputStreamManager.flush(OutputStreamManager.java:156) ... 8 more
2014-10-21 10:39:31,484 ERROR Unable to write to stream //L-Computer1/test/logs/primary.log for appender primeCompressedDaily
log4j2.xml entries is given below,
<?xml version="1.0" encoding="UTF-8"?> <!-- set status below to FATAL to suppress a bug in log4j2: "ERROR appender Failover has no parameter that matches element Failovers" --> <!-- other working value for status is "warn" - --> <Configuration status="warn" name="log4j2" packages="com.ims.log4j"> <Appenders> <Console name="stdout" target="SYSTEM_OUT" ignoreExceptions="false"> <PatternLayout pattern="%d{ABSOLUTE} %1p %X{userinfo} %c{1}:%L - %m%n"/> </Console> <RollingFile name="compressedDaily" fileName="c:/installed/Tomcat-7.0.12/logs/secondary.log" filePattern="c:/installed/Tomcat-7.0.12/logs/secondary.log.%d{yyyy-MM-dd}.gz" ignoreExceptions="false"> <PatternLayout> <Pattern>%d{ABSOLUTE} %1p %X{userinfo} %c{1}:%L - %m%n</Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy/> <SizeBasedTriggeringPolicy/> </Policies> </RollingFile> <RollingFile name="primeCompressedDaily" fileName="//L-Computer1/test/logs/primary.log" filePattern="//L-Computer1/test/logs/primary.log.%d{yyyy-MM-dd}.gz" ignoreExceptions="false" > <PatternLayout> <Pattern>%d{ABSOLUTE} %1p %X{userinfo} %c{1}:%L - %m%n</Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy/> <SizeBasedTriggeringPolicy/> </Policies> </RollingFile> <Failover name="FailoverAppender" primary="primeCompressedDaily" retryInterval="61" ignoreExceptions="false"> <Failovers> <AppenderRef ref="compressedDaily" /> </Failovers> </Failover> <Async name="asyncCompressed"> <AppenderRef ref="FailoverAppender" /> </Async> <Async name="asyncStdout"> <AppenderRef ref="stdout" /> </Async> </Appenders> <Loggers> <Root level="trace"> <AppenderRef ref="asyncCompressed" level="trace"/> <AppenderRef ref="asyncStdout" level="trace"/> </Root> <Logger name="com.ims" level="debug" includeLocation="true" additivity="false"> <AppenderRef ref="asyncCompressed"/> </Logger> <Logger name="org.apache.cxf.interceptor.LoggingInInterceptor" level="info" includeLocation="true" additivity="false"> <AppenderRef ref="asyncCompressed"/> </Logger> <Logger name="org.apache.cxf.interceptor.LoggingOutInterceptor" level="info" includeLocation="true" additivity="false"> <AppenderRef ref="asyncCompressed"/> </Logger> <Logger name="org.hibernate" level="error" includeLocation="true" additivity="false"> <AppenderRef ref="asyncCompressed"/> </Logger> <Logger name="test.escalation" level="debug" includeLocation="true" additivity="false"> <AppenderRef ref="asyncCompressed"/> </Logger> <Logger name="org.apache.cxf" level="info" includeLocation="true" additivity="false"> <AppenderRef ref="asyncCompressed"/> </Logger> </Loggers> </Configuration>
Junit method
@Test public void log4jTest() throws Exception { System.out.println("log4j2 test"); Thread.sleep(30000); log.error("debug-log4j2 test*1"); Thread.sleep(60000); log.error("debug-log4j2 test*2"); Thread.sleep(30000); System.out.println("debug-log4j2 test*3"); Thread.sleep(70000); log.info("debug-log4j2 test*4"); Thread.sleep(30000); log.debug("debug-log4j2 test*5"); Thread.sleep(30000); log.debug("debug-log4j2 test*6"); Thread.sleep(30000); log.debug("debug-log4j2 test*7"); Thread.sleep(30000); log.debug("debug-log4j2 test*8"); Thread.sleep(290000); log.debug("debug-log4j2 test*9"); Thread.sleep(30000); log.debug("debug-log4j2 test*10"); System.out.println("debug-log4j2 test*6"); }
PS Please forgive if I wasn't narrate the problem properly. any quick help in this issue would be highly appreciated.