Variables


In order to ease the usage of often repeated phrases inside parameters jLo offers the possibility to define variables. These variables will be replaced with the defined parameters. Here is a short example:

<?xml version="1.0" ?>
<log-configuration>
  <variables>
    <variable name="base.dir" value="/opt/jboss/jboss/log"/>
  </variables>
.......
  <generator name="DefaultGenerator">
    <formatter class="DefaultFormatter"/>
    <handler class="DateFileHandler>
      <parameter name="file" value="${base.dir}/mylog-${date}.log" />    
      <parameter name="format" value="yyyy-MM-dd"/> 
    </handler>
  </generator>
</log-configuration>

This way you can define a base dir once and then use it for all handlers for example. So changing the base directory means changing only one entry.

System properties


Beside defining your own variables jLo can translate java system properties. These system properties are set by the JVM and are mostly platform dependent. The temp-directory for example differs for every operaring system. In order to build a platform independent configuration you can use these system properties. You need to put the sytem: keyword in front of the property name:

<?xml version="1.0" ?>
<log-configuration>
  .....
  <generator name="DefaultGenerator">
    <formatter class="DefaultFormatter"/>
    <handler class="DateFileHandler">
      <parameter name="file" value="${system:java.io.tmpdir}/mylog-${date}.log" />    
      <parameter name="format" value="yyyy-MM-dd"/> 
    </handler>
  </generator>
</log-configuration>

After the keyword you have to put the name of the system propery. This example will set the tmpdir to the OS specific temp-directory. You can use any system property.

Environment variables


Another way for writing platform indenpendet applications is the use of environment variables. This is an usual at least under Linux/Unix. You can set a home variable to your application. When you want to use an environment variable you have to put the env: keyword in front of the name. Here is a short example:

<?xml version="1.0" ?>
<log-configuration>
  .....
  <generator name="DefaultGenerator">
    <formatter class="DefaultFormatter"/>
    <handler class="DateFileHandler">
      <parameter name="file" value="${env:MY_APP_HOME}/mylog-${date}.log" />    
      <parameter name="format" value="yyyy-MM-dd"/> 
    </handler>
  </generator>
</log-configuration>

This MYAPPHOME can be either "/usr/local/myapp" under Linux or "c:\myapp" under Windows. All you have to do is define such an environment variable and you can move your applications between different OS.