Using conditional processing

Hello, I've been experimenting with logback core/classic 0.9.27 (and slf4j 1.6.1) with Tomcat 6.0.29, Java 1.6 on Solaris for the past couple days, and have hit a wall viz conditional configuration processing. When I include a conditional like the following in my configuration file, nothing in the file is processed beginning with and after that directive: <if condition='property("HOSTNAME").contains("hactar")'> <then> <property name="foo" value="bar"/> </then> </if> Even a conditional as simple as the following causes processing to abort: <if condition='"foo".equals("foo")'> <then> <property name="foo" value="bar"/> </then> </if> No errors seen in the ViewStatusMessagesServlet. Am I doing something wrong? Thanks. /mcr

Hello Michael, Adding a status listener is usually a good idea: <configuration> <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> ... </configuration> Could you post your config file? -- Ceki On 25/01/2011 7:41 PM, Michael C Rosenstein wrote:
Hello, I've been experimenting with logback core/classic 0.9.27 (and slf4j 1.6.1) with Tomcat 6.0.29, Java 1.6 on Solaris for the past couple days, and have hit a wall viz conditional configuration processing.
When I include a conditional like the following in my configuration file, nothing in the file is processed beginning with and after that directive:
<if condition='property("HOSTNAME").contains("hactar")'> <then> <property name="foo" value="bar"/> </then> </if>
Even a conditional as simple as the following causes processing to abort:
<if condition='"foo".equals("foo")'> <then> <property name="foo" value="bar"/> </then> </if>
No errors seen in the ViewStatusMessagesServlet.
Am I doing something wrong?
Thanks.
/mcr

I forgot to mention that conditional processing requires the janino library. On 25/01/2011 7:53 PM, Ceki Gülcü wrote:
Hello Michael,
Adding a status listener is usually a good idea:
<configuration> <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> ... </configuration>
Could you post your config file?
-- Ceki
On 25/01/2011 7:41 PM, Michael C Rosenstein wrote:
Hello, I've been experimenting with logback core/classic 0.9.27 (and slf4j 1.6.1) with Tomcat 6.0.29, Java 1.6 on Solaris for the past couple days, and have hit a wall viz conditional configuration processing.
When I include a conditional like the following in my configuration file, nothing in the file is processed beginning with and after that directive:
<if condition='property("HOSTNAME").contains("hactar")'> <then> <property name="foo" value="bar"/> </then> </if>
Even a conditional as simple as the following causes processing to abort:
<if condition='"foo".equals("foo")'> <then> <property name="foo" value="bar"/> </then> </if>
No errors seen in the ViewStatusMessagesServlet.
Am I doing something wrong?
Thanks.
/mcr
Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

On 1/25/2011 14:58, Ceki Gülcü wrote:
I forgot to mention that conditional processing requires the janino library.
Yes! Adding janino.jar and commons-compiler.jar to the classpath fixed the problem. I must have missed that requirement in the docs. Thank you! For complete clarification, here is an excerpt of my config file: <?xml version="1.0" encoding="UTF-8"?> <configuration debug="true" scan="true" scanPeriod="10 minutes"> <!-- ${catalina.home} is set by tomcat-jsvc.sh. --> <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/> <logger name="org.mdibl.ctd.pwa.admin.web.AppStatus" level="INFO"/> <logger name="org.mdibl.ctd.pwa.servlets.AuthorRedirect" level="INFO"/> <logger name="org.mdibl.ctd.pwa.queries.web.BasicQueryController" level="INFO"/> <!-- Email appender (don't need for dev server). --> <if condition='!property("HOSTNAME").contains("hactar")'> <then> <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> <smtpHost>xxx.xxx.xxx</smtpHost> <to>xxxxxx@xxx.xxx</to> <from>xxxxx@xxx.xxx</from> <subject>${HOSTNAME} %level: %logger{30}</subject> <layout class="ch.qos.logback.classic.html.HTMLLayout"> <pattern>%d%level%logger%msg</pattern> </layout> <cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTrackerImpl"> <bufferSize>128</bufferSize> </cyclicBufferTracker> </appender> <root> <appender-ref ref="EMAIL"/> </root> </then> </if> <!-- Daily rolling file appender (all servers). --> <appender name="RFILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>${catalina.home}/logs/lb_tomcat.log</File> <encoder> <pattern>%d{HH:mm:ss.SSS} %-5level %logger{40} - %msg%n</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- Rollover file daily --> <fileNamePattern>${catalina.home}/logs/tomcat.%d.log</fileNamePattern> <!-- Keep 30 days of history --> <maxHistory>30</maxHistory> </rollingPolicy> </appender> <root level="WARN"> <appender-ref ref="RFILE"/> </root> </configuration>

Without janino.jar on your class path, did logback configuration fail silently? On 25/01/2011 9:26 PM, Michael C Rosenstein wrote:
On 1/25/2011 14:58, Ceki Gülcü wrote:
I forgot to mention that conditional processing requires the janino library.
Yes! Adding janino.jar and commons-compiler.jar to the classpath fixed the problem. I must have missed that requirement in the docs. Thank you!
For complete clarification, here is an excerpt of my config file:
<?xml version="1.0" encoding="UTF-8"?> <configuration debug="true" scan="true" scanPeriod="10 minutes"> <!-- ${catalina.home} is set by tomcat-jsvc.sh. -->
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>
<logger name="org.mdibl.ctd.pwa.admin.web.AppStatus" level="INFO"/>
<logger name="org.mdibl.ctd.pwa.servlets.AuthorRedirect" level="INFO"/>
<logger name="org.mdibl.ctd.pwa.queries.web.BasicQueryController" level="INFO"/>
<!-- Email appender (don't need for dev server). --> <if condition='!property("HOSTNAME").contains("hactar")'> <then> <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> <smtpHost>xxx.xxx.xxx</smtpHost> <to>xxxxxx@xxx.xxx</to> <from>xxxxx@xxx.xxx</from> <subject>${HOSTNAME} %level: %logger{30}</subject> <layout class="ch.qos.logback.classic.html.HTMLLayout"> <pattern>%d%level%logger%msg</pattern> </layout> <cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTrackerImpl"> <bufferSize>128</bufferSize> </cyclicBufferTracker> </appender> <root> <appender-ref ref="EMAIL"/> </root> </then> </if>
<!-- Daily rolling file appender (all servers). --> <appender name="RFILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>${catalina.home}/logs/lb_tomcat.log</File> <encoder> <pattern>%d{HH:mm:ss.SSS} %-5level %logger{40} - %msg%n</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- Rollover file daily -->
<fileNamePattern>${catalina.home}/logs/tomcat.%d.log</fileNamePattern> <!-- Keep 30 days of history --> <maxHistory>30</maxHistory> </rollingPolicy> </appender>
<root level="WARN"> <appender-ref ref="RFILE"/> </root> </configuration>

On 26/01/2011 1:17 AM, Michael C Rosenstein wrote:
On 1/25/11 3:28 PM, Ceki Gülcü wrote:
Without janino.jar on your class path, did logback configuration fail silently?
Yes. Also silently failed w/o commons-compiler.jar.
In the absence of Janino on the classpath, logback should now gracefully skip over the conditional part. -- Ceki

I much prefer things to fail fast and ugly rather than gracefully skipping over and leaving me scratching my head as to why it's working but not the way I expected. ----- Original Message -----
From: "Michael C Rosenstein" <mcr@mdibl.org> To: logback-user@qos.ch Sent: Friday, 4 February, 2011 1:33:56 PM Subject: Re: [logback-user] Using conditional processing
In the absence of Janino on the classpath, logback should now gracefully skip over the conditional part.
I wonder if it should be less graceful and produce an error/warning to indicate that the conditional is going to be ignored? _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

On 04.02.2011 14:45, Robert Elliot wrote:
I much prefer things to fail fast and ugly rather than gracefully skipping over and leaving me scratching my head as to why it's working but not the way I expected.
Fail fast by throwing an exception percolated to the caller? That's incompatible with logback's API which never (or very rarely) throws exceptions visible by the user. Does that make sense? -- Ceki

On 04.02.2011 14:33, Michael C Rosenstein wrote:
In the absence of Janino on the classpath, logback should now gracefully skip over the conditional part.
I wonder if it should be less graceful and produce an error/warning to indicate that the conditional is going to be ignored?
Oh, that is already the case. When it "gracefully" skips over the conditional part, it emits an error message. -- Ceki
participants (4)
-
Ceki Gulcu
-
Ceki Gülcü
-
Michael C Rosenstein
-
Robert Elliot