Using Thread to monitored TimeBasedRollingPolicy...!

Dear sir, Yesterday night, i tried TimeBasedRollingPolicy class to logs the my code part. i used below configuration code in XML and after, used a single Thread to runs full night... When i see today morning, file created (myDebug.2009-04-02.zip) successfully. i extracted zip file after i verified yesterday log file. But, When see a current log file it keeps both logs (means yesterday and today logs). Actually this current log should contain today log only... i don't where am doing problem.... Please HELP me out... <appender name="FILEDEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>Debug/myDebug.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>myDebug.%d.zip</FileNamePattern> <MaxHistory>60</MaxHistory> </rollingPolicy> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</Pattern> </layout> </appender> Thank you, boss134 -- View this message in context: http://www.nabble.com/Using-Thread-to-monitored-TimeBasedRollingPolicy...%21... Sent from the Logback Dev mailing list archive at Nabble.com.

Can you send the complete configuration file you are using? boss134 wrote:
<appender name="FILEDEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>Debug/myDebug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>myDebug.%d.zip</FileNamePattern> <MaxHistory>60</MaxHistory> </rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter>
<layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</Pattern> </layout>
</appender>
Thank you, boss134
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Dear sir, below part is my complete configuration... includes xml configuration and java code part i logging every level in separate log file..... <configuration> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <ImmediateFlush>true</ImmediateFlush> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</Pattern> </layout> </appender> <appender name="FILEDEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>Debug/myDebug.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>myDebug.%d.zip</FileNamePattern> <!-- keep 60 days worth of history --> <MaxHistory>60</MaxHistory> </rollingPolicy> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</Pattern> </layout> </appender> <appender name="FILEINFO" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>Information/myInfo.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>myInfo.%d.log</FileNamePattern> <!-- keep 60 days worth of history --> <MaxHistory>60</MaxHistory> </rollingPolicy> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</Pattern> </layout> </appender> <appender name="FILEWARN" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>Warning/myWarn.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>myWarn.%d.log</FileNamePattern> <!-- keep 60 days worth of history --> <MaxHistory>60</MaxHistory> </rollingPolicy> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>WARN</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</Pattern> </layout> </appender> <appender name="FILERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>Error/myError.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>myError.%d.zip</FileNamePattern> <!-- keep 60 days worth of history --> <MaxHistory>60</MaxHistory> </rollingPolicy> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</Pattern> </layout> </appender> <root level="debug"> <appender-ref ref="CONSOLE" /> <appender-ref ref="FILEDEBUG" /> <appender-ref ref="FILEINFO" /> <appender-ref ref="FILEWARN" /> <appender-ref ref="FILERROR" /> </root> </configuration> ================================================================================== COMPLETE JAVA CODE ================================================================================== import java.util.Random; import java.util.Scanner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.core.util.StatusPrinter; public class LogBackTester implements Runnable { /** Monitor Thread Status */ private volatile boolean threadStatus = false; /** Logger */ final static Logger logger = LoggerFactory.getLogger(LogBackTester.class); public LogBackTester() { try { // LogBack Configuration LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator config = new JoranConfigurator(); config.setContext(loggerContext); loggerContext.reset(); config.doConfigure(".\\src\\logback.xml"); StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext); } catch (Exception e) { e.printStackTrace(); } } public void run() { int minValue = 500; int maxValue = 1000; Random random = new Random(); while(!threadStatus) { int randomValue = random.nextInt(maxValue - minValue + 1) + minValue; // Write All logs here System.err.println("Random Value : " + randomValue); logger.trace("Trace {} " + randomValue); logger.debug("Debug {} " + randomValue); logger.info("Information {} " + randomValue); logger.warn("Warning {} " + randomValue); logger.error("Error {} " + randomValue); try { Thread.sleep(randomValue); } catch (InterruptedException e) { e.printStackTrace(); } } } private void logBackThreadKiller() { Scanner scan = new Scanner(System.in); String str = scan.next(); while(scan.hasNext()) { str = scan.next(); if(true == str.equalsIgnoreCase("Y")) { threadStatus = true; break; } } scan.close(); } public static void main(String[] args) { LogBackTester tester = new LogBackTester(); Thread thread = new Thread(tester, "LogBackTester"); thread.start(); // Thread Killer tester.logBackThreadKiller(); } } Thank you, boss134 -- View this message in context: http://www.nabble.com/Using-Thread-to-monitored-TimeBasedRollingPolicy...%21... Sent from the Logback Dev mailing list archive at Nabble.com.

The config file looks OK. Separating into different files per log level is probably not a good practice, but that is unrelated to the problem at hand. You also don't want to write logger.trace("Trace {} " + randomValue); but logger.trace("Trace {}", randomValue); instead. However, this is also unrelated to the problem at hand. I suspect that for one reason or another, logback is unable to compress the log file, possibly because another process is holding a lock on the file. When this happens, logback will complain by adding a status message in an internal buffer. To see logback's internal errors, you should stop printing messages on the console. Instead, add a status listener which will print status messages generated by logback. The code is: LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); ... // additional line of code loggerContext.getStatusManager().add(new OnConsoleStatusListener()); Also, in your messages consider "hello" as a salutation instead of "Dear sir". boss134 wrote:
Dear sir,
below part is my complete configuration... includes xml configuration and java code part i logging every level in separate log file.....
<configuration> ... [snip]
boss134
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Thanks for your HELP... -- View this message in context: http://www.nabble.com/Using-Thread-to-monitored-TimeBasedRollingPolicy...%21... Sent from the Logback Dev mailing list archive at Nabble.com.
participants (2)
-
boss134
-
Ceki Gulcu