[logback-user] Is it possible to set a defined property with a new value?

LogbackUser amits.84 at gmail.com
Fri Apr 22 16:14:00 CEST 2011


For some reason both the suggested approaches do not work -
To try out the approaches in a standalone environment I am using a system
property instead of a JNDI one.

I add the following the logback.xml to try the first suggested approach

    <property name="LOG_LOCATION" value="${loglocation}"/>

    <if condition='property("LOG_LOCATION").equals("")'>
        <then>
            <property name="LOG_LOCATION" value="E://Temp//Logs"/>
        </then>
    </if>

The outcome is that a directory named loglocation_IS_UNDEFINED is created
under the current working directory.

First approach is preferred then the second one (<file>${LOG_LOCATION:-some
default}/blah.log</file>) since declaring the log location property at the
start is helpful and can be used by all the file appenders declared in the
log file.

Is using a system property instead of a JNDI causing the problem ?


Ceki Gulcu wrote:
> 
> On 21.04.2011 14:45, LogbackUser wrote:
>>
>> Below is something what I want to achieve
>>
>>      <insertFromJNDI env-entry-name="LogLocation" as="LOG_LOCATION"/>
>>
>>      <if condition='property("LOG_LOCATION").equals("")'>
>>          <then>
>>              <!--how do I reset the LOG_LOCATION property here-->
>>          </then>
>>      </if>
>>
>> Basically I want to set the LOG_LOCATION property to be set to a default
>> value if the JNDI entry is not present. What currently happens is - if
>> the
>> JNDI property is not defined it assigns the property named "LOG_LOCATION"
>> to
>> "LOG_LOCATION_IS_UNDEFINED".
>>
>> Thank you in advance.
> 
> Hello,
> 
> You have several options available to you.
> 
> You can either set the default value for LOG_LOCATION if it is 
> undefined. Here is how:
> 
>   <insertFromJNDI env-entry-name="LogLocation" as="LOG_LOCATION"/>
> 
>   <if condition='property("LOG_LOCATION").equals("")'>
>     <then>
>       <property name="LOG_LOCATION" value="some default" />
>     </then>
>   </if>
> 
> You can also make use of the Default substitution feature [1]:
> 
> <insertFromJNDI env-entry-name="LogLocation" as="LOG_LOCATION"/>
> 
> <appender class="ch.qos.logback.core.FileAppender>
>    <file>${LOG_LOCATION:-some default}/blah.log</file>
>    ....
> </appender>
> 
> HTH,
> 
> [1] 
> http://logback.qos.ch/manual/configuration.html#defaultValuesForVariables
> 
> -- 
> Ceki
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
> 
> 

-- 
View this message in context: http://old.nabble.com/Is-it-possible-to-set-a-defined-property-with-a-new-value--tp31449154p31456647.html
Sent from the Logback User mailing list archive at Nabble.com.



More information about the Logback-user mailing list