[logback-user] Filter does not work on tomcat
Sager, Patrick
patrick.sager at roche.com
Thu Jun 17 17:36:23 CEST 2010
Hello HTH
I don't think that isEmpty() is the problem, as this method does exist since Java 1.6.
Furthermore, when using an unknown method, janino throws a corresponding exception. E.g.,
17:32:25,398 |-ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator at 1064a6d - Could not start evaluator with expression [((String)mdc.get("source").foe() != null)] org.codehaus.commons.compiler.CompileException: Line 2, Column 31: A method named "foe" is not declared in any enclosing class nor any supertype, nor through a static import
at org.codehaus.commons.compiler.CompileException: Line 2, Column 31: A method named "foe" is not declared in any enclosing class nor any supertype, nor through a static import
at at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:9013)
at at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:6548)
at at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3428)
...
Furthermore, the filter works correctly when running within my JUnit tests.
My guess is, that mdc is null.
Do I somehow need to initialize it?
Best regards
-- Patrick
-----Original Message-----
From: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch] On Behalf Of Ceki Gülcü
Sent: Thursday, June 17, 2010 5:16 PM
To: logback users list
Subject: Re: [logback-user] Filter does not work on tomcat
Hello Patrick,
It looks like there is a problem in the evaluator expression, that is
in (mdc.get("source") != null) && !((String)mdc.get("source")).isEmpty()
For one, isEmtpty() is not a java.lang.String method.
HTH,
On 17/06/2010 4:48 PM, Sager, Patrick wrote:
> Hello
>
> Thanks for your fast reply.
>
> I checked that janino.jar is deployed.
> However, when I add the statuslistener to the configuration file,
> logback writes the following exception:
>
> 16:39:24,539 |-ERROR in
> ch.qos.logback.core.filter.EvaluatorFilter at 151aa16 - Evaluator null
> threw an exception ch.qos.logback.core.boolex.EvaluationException:
> Evaluator [null] caused an exception
> at ch.qos.logback.core.boolex.EvaluationException: Evaluator
> [null] caused an exception
> at at
> ch.qos.logback.core.boolex.JaninoEventEvaluatorBase.evaluate(JaninoEvent
> EvaluatorBase.java:80)
> at at
> ch.qos.logback.core.filter.EvaluatorFilter.decide(EvaluatorFilter.java:6
> 5)
> at at
> ch.qos.logback.core.spi.FilterAttachableImpl.getFilterChainDecision(Filt
> erAttachableImpl.java:52)
> at at
> ch.qos.logback.core.UnsynchronizedAppenderBase.getFilterChainDecision(Un
> synchronizedAppenderBase.java:141)
> at at
> ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAp
> penderBase.java:86)
> at at
> ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(App
> enderAttachableImpl.java:64)
> at at
> ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:283)
> at at
> ch.qos.logback.classic.Logger.callAppenders(Logger.java:270)
> at at
> ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:471
> )
> at at
> ch.qos.logback.classic.Logger.filterAndLog_1(Logger.java:443)
> at at ch.qos.logback.classic.Logger.debug(Logger.java:536)
> at at
> com.roche.dp.rss.gateway.configuration.tools.LogManager.setLogSeverity(L
> ogManager.java:141)
> at at
> com.roche.dp.rss.gateway.configuration.tools.LogManager.clearLog(LogMana
> ger.java:88)
> at at
> com.roche.dp.rss.gateway.userinterfaces.backing.Log.purgeLog(Log.java:34
> )
> at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
> at at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
> a:57)
> at at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
> Impl.java:43)
> at at java.lang.reflect.Method.invoke(Method.java:616)
> at at
> org.apache.el.parser.AstValue.invoke(AstValue.java:191)
> at at
> org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
> at at
> com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:
> 68)
> at at
> javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(Method
> BindingMethodExpressionAdapter.java:88)
> at at
> com.sun.faces.application.ActionListenerImpl.processAction(ActionListene
> rImpl.java:102)
> at at
> javax.faces.component.UICommand.broadcast(UICommand.java:387)
> at at
> org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:324)
> at at
> org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:29
> 9)
> at at
> org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:256)
> at at
> org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java
> :469)
> at at
> com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplication
> Phase.java:82)
> at at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
> at at
> com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
> at at
> javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
> at at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tionFilterChain.java:290)
> at at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erChain.java:206)
> at at
> org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
> at at
> org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
> at at
> org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter
> .java:388)
> at at
> org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
> at at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tionFilterChain.java:235)
> at at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erChain.java:206)
> at at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
> e.java:233)
> at at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
> e.java:191)
> at at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
> :127)
> at at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
> :102)
> at at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
> java:109)
> at at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
> 98)
> at at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85
> 2)
> at at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
> Http11Protocol.java:588)
> at at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> at at java.lang.Thread.run(Thread.java:636)
> Caused by: java.lang.reflect.InvocationTargetException
> at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
> at at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
> a:57)
> at at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
> Impl.java:43)
> at at java.lang.reflect.Method.invoke(Method.java:616)
> at at
> org.codehaus.janino.ScriptEvaluator.evaluate(ScriptEvaluator.java:931)
> at at
> org.codehaus.janino.ScriptEvaluator.evaluate(ScriptEvaluator.java:349)
> at at
> ch.qos.logback.core.boolex.JaninoEventEvaluatorBase.evaluate(JaninoEvent
> EvaluatorBase.java:73)
> at ... 49 common frames omitted
> Caused by: java.lang.NullPointerException
> at at SC.eval0(SC.java:2)
> at ... 56 common frames omitted
>
> P.S.
> Sorry about the format of the mail. I'm currently not receiving the
> mails from this group in my inbox and therefore, I had to fetch it from
> the archive.
>
>
> rom ceki at qos.ch Wed Jun 16 17:13:47 2010
> From: ceki at qos.ch (=?ISO-8859-1?Q?Ceki_G=FClc=FC?=)
> Date: Wed, 16 Jun 2010 17:13:47 +0200
> Subject: [logback-user] Filter does not work on tomcat
> In-Reply-To:
> <912DB9C0846F3042A4BB7FDA0962FCA61037C64F at rkamsem1.emea.roche.com>
> References:
> <912DB9C0846F3042A4BB7FDA0962FCA61037C64F at rkamsem1.emea.roche.com>
> Message-ID:<4C18EA2B.20104 at qos.ch>
>
>
> Hello Patrick,
>
> To see any errors emitted by the EvaluatorFilter, I suggest adding the
> following line to you configuration file:
>
> <statusListener
> class="ch.qos.logback.core.status.OnConsoleStatusListener" />
>
> By the way, have you placed janino.jar in your web-application's class
> path?
>
> HTH,
>
> On 16/06/2010 4:45 PM, Sager, Patrick wrote:
>> Hello
>>
>> I'm using a filter expression to determine the format of my log
> message.
>> When running the configuration within my JUnit tests, the filter works
>> perfectly.
>> However, when running on a tomcat v6.0 server (within eclipse), the
>> filter gets ignored and all log entries are written twice.
>>
>> Here's the extract of my logback.xml file:
>>
>> <!-- Log file for events with an explicitly defined source -->
>> <appender name="ROLLING_LOG_WITH_SOURCE"
>> class="ch.qos.logback.core.rolling.RollingFileAppender">
>> <!-- Accept only messages with an explicit source -->
>> <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
>>
>> <evaluator>
>> <expression>(mdc.get("source") != null)&&
>> !((String)mdc.get("source")).isEmpty()</expression>
>> </evaluator>
>> <OnMatch>ACCEPT</OnMatch>
>> <OnMismatch>DENY</OnMismatch>
>> </filter>
>> <file>/etc/foe/logs/LogFile.log</file>
>> <rollingPolicy
>> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
>> <!-- rollover monthly and compression of log history -->
>>
>> <fileNamePattern>TestLogFile-%d{yyyy-MM}.%i.zip</fileNamePattern>
>> <maxHistory>12</maxHistory>
>> <timeBasedFileNamingAndTriggeringPolicy
>>
>> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
>> <!-- or whenever the file size reaches 1MB -->
>> <maxFileSize>1MB</maxFileSize>
>> </timeBasedFileNamingAndTriggeringPolicy>
>> </rollingPolicy>
>> <encoder>
>> <pattern>%-5level %date{yyyy-MM-dd HH:mm:ss.SSS}
> [%thread]
>> [%X{source}] %msg%n</pattern>
>> </encoder>
>> </appender>
>>
>> <!-- Log file for events with no explicitly defined source -->
>> <appender name="ROLLING_LOG_WITHOUT_SOURCE"
>> class="ch.qos.logback.core.rolling.RollingFileAppender">
>> <!-- Accept discard messages with an explicit source -->
>> <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
>>
>> <evaluator>
>> <expression>(mdc.get("source") != null)&&
>> !((String)mdc.get("source")).isEmpty()</expression>
>> </evaluator>
>> <OnMatch>DENY</OnMatch>
>> <OnMismatch>ACCEPT</OnMismatch>
>> </filter>
>> <file>/etc/foe/logs/LogFile.log</file>
>> <rollingPolicy
>> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
>> <!-- rollover monthly and compression of log history -->
>>
>> <fileNamePattern>TestLogFile-%d{yyyy-MM}.%i.zip</fileNamePattern>
>> <maxHistory>12</maxHistory>
>> <timeBasedFileNamingAndTriggeringPolicy
>>
>> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
>> <!-- or whenever the file size reaches 1MB -->
>> <maxFileSize>1MB</maxFileSize>
>> </timeBasedFileNamingAndTriggeringPolicy>
>> </rollingPolicy>
>> <encoder>
>> <pattern>%-5level %date{yyyy-MM-dd HH:mm:ss.SSS}
> [%thread]
>> [%file:%line] %msg%n</pattern>
>> </encoder>
>> </appender>
>>
>> Is this a known issue, that LogBack does not support filters under
>> tomcat?
>>
>> Thanks for any help
>> -- Patrick
_______________________________________________
Logback-user mailing list
Logback-user at qos.ch
http://qos.ch/mailman/listinfo/logback-user
More information about the Logback-user
mailing list