<div dir="ltr">That worked out of the box, thanks a lot four your help. I had missed the fact that the RequestLogImpl was in fact the context. </div><div class="gmail_extra"><br><div class="gmail_quote">On 25 January 2017 at 09:09, Ceki Gülcü <span dir="ltr"><<a href="mailto:ceki@qos.ch" target="_blank">ceki@qos.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
LoggerContext is the context for logback-classic whereas RequestLogImpl<br>
*is* the context for logback-access+Jetty. You need to set requestLog (of type RequestLogImpl) as the context for components such as RollingFileAppender and TimeBasedRollingPolicy. By the way, all logback components must be started. Otherwise, they will not work.<br>
<br>
As such, here a revised version which should work better. Beware, I have not tested this code and it may still contain some wrinkles. Without further ado here is the code:<br>
<br>
RequestLogImpl requestLog = new RequestLogImpl(); // implements Context<br>
<br>
ch.qos.logback.access.PatternL<wbr>ayoutEncoder encoder = new ch.qos.logback.access.PatternL<wbr>ayoutEncoder();<br>
encoder.setContext(requestLog)<wbr>;<br>
encoder.setPattern("combined")<wbr>;<br>
encoder.start(); // // components must be started<br>
<br>
RollingFileAppender<IAccessEve<wbr>nt> appender = new RollingFileAppender<IAccessEve<wbr>nt>();<br>
appender.setContext(requestLog<wbr>); // requestLog is the context<span class=""><br>
appender.setName("REQUESTLOG")<wbr>;<br>
appender.setFile("/bps/log/req<wbr>uest/myrequest.log");<br></span>
appender.setEncoder(encoder);<br>
<br>
<br>
TimeBasedRollingPolicy<IAccess<wbr>Event> timePolicy = new TimeBasedRollingPolicy<IAccess<wbr>Event>();<span class=""><br>
<br>
<br>
timePolicy.setFileNamePattern(<wbr>"/bps/log/archive/request/my_r<wbr>equest_%d{yyyy-MM-dd}_%d{HH_mm<wbr>_ss,aux}.log.zip");<br></span>
timePolicy.setContext(requestL<wbr>og); // requestLog is the context<span class=""><br>
timePolicy.setMaxHistory(30);<br>
timePolicy.setTimeBasedFileNam<wbr>ingAndTriggeringPolicy(new StartupTimeBasedTriggeringPoli<wbr>cy<IAccessEvent>());<br>
timePolicy.setParent(appender)<wbr>;<br></span>
timePolicy.start(); // components must be started<br>
<br>
appender.setRollingPolicy(time<wbr>Policy);<br>
appender.setTriggeringPolicy(t<wbr>imePolicy);<br>
<br>
appender.start(); // // components must be started<br>
requestLog.addAppender(appende<wbr>r);<br>
<br>
Let us know how it goes.<br>
<br>
--<br>
Ceki<br>
<br>
On 1/25/2017 8:20, Jan-Olav Eide wrote:<br>
<br>
[snip]<span class=""><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This does not work (it archives etc, but never any contents in the file) :<br>
<br>
LoggerContext loggerContext =<br>
LoggerContext.class.cast(Logge<wbr>rFactory.getILoggerFactory());<br>
</blockquote>
<br>
<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
RollingFileAppender<IAccessEve<wbr>nt> appender = new<br>
RollingFileAppender<>();<br>
appender.setName("REQUESTLOG")<wbr>;<br>
appender.setFile("/bps/log/req<wbr>uest/myrequest.log");<br>
TimeBasedRollingPolicy<IAccess<wbr>Event> timePolicy = new<br>
TimeBasedRollingPolicy<>();<br>
<br>
timePolicy.setFileNamePattern(<wbr>"/bps/log/archive/request/my_r<wbr>equest_%d{yyyy-MM-dd}_%d{HH_mm<wbr>_ss,aux}.log.zip");<br>
timePolicy.setContext(loggerCo<wbr>ntext);<br>
timePolicy.setMaxHistory(30);<br>
timePolicy.setTimeBasedFileNam<wbr>ingAndTriggeringPolicy(new<br>
StartupTimeBasedTriggeringPoli<wbr>cy<IAccessEvent>());<br>
timePolicy.setParent(appender)<wbr>;<br>
appender.setRollingPolicy(time<wbr>Policy);<br>
appender.setTriggeringPolicy(t<wbr>imePolicy);<br>
PatternLayoutEncoder encoder = new PatternLayoutEncoder();<br>
encoder.setPattern("combined")<wbr>;<br>
appender.setEncoder(encoder);<br>
RequestLogImpl requestLog = new RequestLogImpl();<br>
requestLog.addAppender(appende<wbr>r);<br>
<br>
On 24 January 2017 at 22:04, Ceki Gülcü <<a href="mailto:ceki@qos.ch" target="_blank">ceki@qos.ch</a><br></span><span class="">
<mailto:<a href="mailto:ceki@qos.ch" target="_blank">ceki@qos.ch</a>>> wrote:<br>
<br>
<br>
Hi Jan-Olav,<br>
<br>
It's not possible to tell without seeing the code in question. Would<br>
you want to post it here?<br>
<br>
--<br>
Ceki<br>
<br>
On 1/24/2017 19:43, Jan-Olav Eide wrote:<br>
<br>
> Well, things worked much better with a logback-access.xml file rather<br>
> than a programmatic construction of the same configuration. Strange,<br>
> since the latter code works fine elsewhere.<br>
<br>
<br>
</span></blockquote><div class="HOEnZb"><div class="h5">
______________________________<wbr>_________________<br>
logback-user mailing list<br>
<a href="mailto:logback-user@qos.ch" target="_blank">logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/<wbr>listinfo/logback-user</a></div></div></blockquote></div><br></div>