
Dear Logback Users I am going to use logback in one of my android projects. I have configured everything and it is working perfectly fine. I have used logback-android-1.0.10-2.jar slf4j-api-1.7.5.jar Is it one of the stable versions that I am using? If not, is it possible for you to suggest the stable version? I am planning to have my application on Google Play by next week, is it ok to use logback or there isn't any stable release yet? Also, if everything is fine, I would like to know how can I configure a Rolling file appender with rolling time of 4 hours? Is it possible? Please suggest. I will appreciate all your help. -- Thanks & Regards Jagmohan Singh

On Thu, Jun 27, 2013 at 12:55 AM, Jagmohan Singh <jagmohan.singh.1@gmail.com
wrote:
I have used logback-android-1.0.10-2.jar slf4j-api-1.7.5.jar
Is it one of the stable versions that I am using? If not, is it possible for you to suggest the stable version?
Yes, logback-android-1.0.10-2.jar is the latest stable release.
Also, if everything is fine, I would like to know how can I configure a Rolling file appender with rolling time of 4 hours? Is it possible?
Not out of the box. Currently, the TimeBasedRollingPolicy[1] rolls over files at the beginning of a time period (rather than at specific multiples). There might be an easier (or more correct) way to accomplish your goal, but I suggest overriding the period computation within the triggering policy of TimeBasedRollingPolicy. Here's some *untested* code (at the moment, I don't have my development environment handy to verify any of this). Make this triggering-policy class available on your classpath (e.g., by compiling it into a JAR, and then putting the JAR in your libs directory at the root of your apk): package com.example; public class MyTimeBasedTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> { private int multiple = 1; public void setTimeMultiple(int multiple) { this.multiple = multiple; } @Override protected void computeNextCheck() { super.computeNextCheck(); nextCheck *= multiple; } } Then, in your logback.xml: <configuration> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>logFile.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- hourly rollover --> <fileNamePattern>logFile.%d{yyyy-MM-dd_HH}.log</fileNamePattern> <!-- make that every 4 hours --> <timeBasedFileNamingAndTriggeringPolicy class="com.example.MyTimeBasedTriggeringPolicy"> <timeMultiple>4</timeMultiple> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> </encoder> </appender> <root level="DEBUG"> <appender-ref ref="FILE" /> </root> </configuration> [1] http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy

On Fri, Jun 28, 2013 at 12:19 PM, Tony Trinh <tony19@gmail.com> wrote:
Then, in your logback.xml:
Just noticed the file paths in my example were not absolute paths, which are required in logback-android. I've corrected the example below. <configuration>
<property name="LOG_DIR" value="/data/data/com.example/files/logback" />
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${LOG_DIR}/logFile.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- hourly rollover --> <fileNamePattern>${LOG_DIR}/logFile.%d{yyyy-MM-dd_HH}.log</ fileNamePattern>
<!-- make that every 4 hours --> <timeBasedFileNamingAndTriggeringPolicy class="com.example.MyTimeBasedTriggeringPolicy"> <timeMultiple>4</timeMultiple> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy>
<encoder> <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> </encoder> </appender>
<root level="DEBUG"> <appender-ref ref="FILE" /> </root> </configuration>
participants (2)
-
Jagmohan Singh
-
Tony Trinh