
Hello Ralph, I actually agree with you and would expect some mockery. XML does NOT provide a good basis for a programming language. I don't intend to go beyond if-then-else, i.e. there won't be 'for' or 'while' loops. However, having parts of the config file conditioned on the host seems useful. It is more convenient to deal with a single file with some conditional parts than shuffling around 2 or 3 files 90% identical. A groovy or scala DSL for logback configuration would make sense and would be much cooler then what I am trying to accomplish in XML. We should have a page proposing tasks for volunteers and hope that one of the readers writes a DSL. As for adding support for Messages, it is on my todo list. However, to be honest, there are other items which come beforehand. Cheers, On 30/03/2010 7:27 AM, Ralph Goers wrote:
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