[logback-dev] if-then-else support in Joran.

Ralph Goers rgoers at apache.org
Tue Mar 30 07:27:41 CEST 2010


This just feels overly complicated.  I have a feeling you are going to get pushback from all the folks who have learned over the years that XML is a good configuration language but sucks as a programming language. Wouldn't it make more sense to just use a real scripting language if you want this?

I find it odd that you find this more important than adding support for Messages.

Ralph

On Mar 29, 2010, at 2:07 PM, Ceki Gülcü wrote:

> 
> Just committed new code so that the following configuration file is
> interpreted correctly.
> 
> <configuration>
> 
>  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
>    <file>${randomOutputDir}/conditional.log</file>
>    <encoder>
>      <pattern>%d %-5level %logger{35} - %msg %n</pattern>
>   </encoder>
>  </appender>
> 
>  <root level="ERROR">
>     <appender-ref ref="FILE" />
>  </root>
> 
> 
>  <if condition='property("HOSTNAME").contains("${aHost}")'>
>    <then>
>      <appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
>        <encoder>
>          <pattern>%d %-5level %logger{35} - %msg %n</pattern>
>        </encoder>
>      </appender>
>      <root>
>        <appender-ref ref="CON" />
>      </root>
>    </then>
>  </if>
> 
> </configuration>
> 
> where "aHost" is set to be the name of the current host. Note that
> HOSTNAME always contains the name of the current host so that the
> condition property("HOSTNAME").contains("${aHost}") evaluates to true.
> 
> In my previous message, the config file get set the incremental
> attribute of the root element to true. No such attribute
> exists. Logger declaration in logback configuration files are
> incremental by design. I mistakenly thought that it was like in log4j
> where each logger declaration removes all attached appenders.
> 
> I hope that you'll find the XML-conditional syntax not too
> horrible. Your comments are welcome,
> 
> --
> Ceki
> 
> 
> On 29/03/2010 9:50 PM, Ceki Gülcü wrote:
>> 
>> Hello all,
>> 
>> I began implementing if-then-else support in Joran. If you wish to
>> enable part of a config file in one environment and disable it
>> another, now you can.
>> 
>> Here is an example,
>> 
>> <configuration>
>> 
>> <appender name="FILE" class="ch.qos.logback.core.FileAppender">
>> <encoder>
>> <pattern>%d %-5level %logger{35} - %msg %n</pattern>
>> </encoder>
>> </appender>
>> 
>> <root level="DEBUG">
>> <appender-ref ref="FILE" />
>> </root>
>> 
>> 
>> <if condition='property("HOSTNAME").contains("mydevHost")'>
>> <then>
>> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
>> <encoder>
>> <pattern>%d %-5level %logger{35} - %msg %n</pattern>
>> </encoder>
>> </appender>
>> <root incremental="true">
>> <appender-ref ref="STDOUT" />
>> </root>
>> </then>
>> </if>
>> 
>> </configuration>
>> 
>> Thus, the ConsoleAppender will be attached to the root logger only on
>> "mydevHost" but not on other hosts.
>> 
>> This feature is still experimental. Your feedback is welcome.
>> 
>> --
>> Ceki
>> 
>> _______________________________________________
>> logback-dev mailing list
>> logback-dev at qos.ch
>> http://qos.ch/mailman/listinfo/logback-dev
> 
> _______________________________________________
> logback-dev mailing list
> logback-dev at qos.ch
> http://qos.ch/mailman/listinfo/logback-dev



More information about the logback-dev mailing list