
Got bitten by HandlerCollection vs HandlerList, which have different semantics. Works fine with a HandlerCollection. On 31 January 2017 at 13:56, Jan-Olav Eide <janolaveide@gmail.com> wrote:
Well, I cheered a bit too soon...
handlers.addHandler(logbackInlinedRequestHandler()); handlers.addHandler(webappHandler(contextPath(), warURL()));
This causes no data being available on the InputStream of the servlet inside the webapp. Reversing the order of the handler registrations causes nothing to be request-logged, Probably for the same reason, the data is consumed by the servlet.
Should not the logback handler be non-invasive in that it should put the data back on the InputStream, or am I missing something here ?
On 25 January 2017 at 09:50, Jan-Olav Eide <janolaveide@gmail.com> wrote:
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.
On 25 January 2017 at 09:09, Ceki Gülcü <ceki@qos.ch> wrote:
LoggerContext is the context for logback-classic whereas RequestLogImpl *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.
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:
RequestLogImpl requestLog = new RequestLogImpl(); // implements Context
ch.qos.logback.access.PatternLayoutEncoder encoder = new ch.qos.logback.access.PatternLayoutEncoder(); encoder.setContext(requestLog); encoder.setPattern("combined"); encoder.start(); // // components must be started
RollingFileAppender<IAccessEvent> appender = new RollingFileAppender<IAccessEvent>(); appender.setContext(requestLog); // requestLog is the context appender.setName("REQUESTLOG"); appender.setFile("/bps/log/request/myrequest.log"); appender.setEncoder(encoder);
TimeBasedRollingPolicy<IAccessEvent> timePolicy = new TimeBasedRollingPolicy<IAccessEvent>();
timePolicy.setFileNamePattern("/bps/log/archive/request/my_r equest_%d{yyyy-MM-dd}_%d{HH_mm_ss,aux}.log.zip"); timePolicy.setContext(requestLog); // requestLog is the context timePolicy.setMaxHistory(30); timePolicy.setTimeBasedFileNamingAndTriggeringPolicy(new StartupTimeBasedTriggeringPolicy<IAccessEvent>()); timePolicy.setParent(appender); timePolicy.start(); // components must be started
appender.setRollingPolicy(timePolicy); appender.setTriggeringPolicy(timePolicy);
appender.start(); // // components must be started requestLog.addAppender(appender);
Let us know how it goes.
-- Ceki
On 1/25/2017 8:20, Jan-Olav Eide wrote:
[snip]
This does not work (it archives etc, but never any contents in the file)
:
LoggerContext loggerContext = LoggerContext.class.cast(LoggerFactory.getILoggerFactory());
RollingFileAppender<IAccessEvent> appender = new
RollingFileAppender<>(); appender.setName("REQUESTLOG"); appender.setFile("/bps/log/request/myrequest.log"); TimeBasedRollingPolicy<IAccessEvent> timePolicy = new TimeBasedRollingPolicy<>();
timePolicy.setFileNamePattern("/bps/log/archive/request/my_r equest_%d{yyyy-MM-dd}_%d{HH_mm_ss,aux}.log.zip"); timePolicy.setContext(loggerContext); timePolicy.setMaxHistory(30); timePolicy.setTimeBasedFileNamingAndTriggeringPolicy(new StartupTimeBasedTriggeringPolicy<IAccessEvent>()); timePolicy.setParent(appender); appender.setRollingPolicy(timePolicy); appender.setTriggeringPolicy(timePolicy); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setPattern("combined"); appender.setEncoder(encoder); RequestLogImpl requestLog = new RequestLogImpl(); requestLog.addAppender(appender);
On 24 January 2017 at 22:04, Ceki Gülcü <ceki@qos.ch <mailto:ceki@qos.ch>> wrote:
Hi Jan-Olav,
It's not possible to tell without seeing the code in question. Would you want to post it here?
-- Ceki
On 1/24/2017 19:43, Jan-Olav Eide wrote:
> Well, things worked much better with a logback-access.xml file rather > than a programmatic construction of the same configuration. Strange, > since the latter code works fine elsewhere.
_______________________________________________ logback-user mailing list logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user