Note that there are some explanatory texts on larger screens.

plurals
  1. POLogBack RollingFileAppender Not Writing Log File (Though FileAppender works)
    text
    copied!<p>I'm trying to programmatically configure LogBack's <code>RollingFileAppender</code> (<code>ch.qos.logback.core.rolling.RollingFileAppender</code>) and it doesn't seem to be working. When I'm using <code>FileAppender</code>, everything seems to be working fine with exact same configuration (less policies/trigger) so I'm guessing it's not a permission issue. I tried commenting out all policy configuration and that didn't help either. Below is my sample code, with some hard-coded values. Also, there's no error at all what so ever. When I debug the LogBack source code, I didn't see anything that could have gone wrong.</p> <p>Any hint is appreciative. I need to get this working without a configuration file since that's a restriction in my organization. I'm testing this out on a MacBook.</p> <pre><code>Logger logger = (Logger)LoggerFactory.getLogger(applicationName); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); lc.reset(); RollingFileAppender&lt;ILoggingEvent&gt; fileAppender = new RollingFileAppender&lt;ILoggingEvent&gt;(); fileAppender.setAppend(true); fileAppender.setFile("/Users/Jack/Desktop/logs/" + applicationName + ".log"); fileAppender.setContext(lc); SizeBasedTriggeringPolicy&lt;ILoggingEvent&gt; rPolicy = new SizeBasedTriggeringPolicy&lt;ILoggingEvent&gt;("20MB"); fileAppender.setTriggeringPolicy(rPolicy); TimeBasedRollingPolicy&lt;ILoggingEvent&gt; tPolicy = new TimeBasedRollingPolicy&lt;ILoggingEvent&gt;(); tPolicy.setFileNamePattern("/archive/" + applicationName + ".%d"); tPolicy.setMaxHistory(180); tPolicy.setParent(fileAppender); tPolicy.setContext(lc); PatternLayout pl = new PatternLayout(); pl.setPattern("%d %5p %t [%c:%L] %m%n)"); pl.setContext(lc); pl.start(); fileAppender.setLayout(pl); fileAppender.start(); logger.addAppender(fileAppender); logger.setLevel(Level.DEBUG); logger.debug("Test message"); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload