Deepa,


I think you have answered your own question. If a config file requires data specific to each program, then there is no way to initialize two programs with the same config file unless the relevant parts are parsed *conditionally*. Conditional parsing is not supported by which log4j 1.2, nor by 1.3, although it could be added to the latter.

HTH,

At 11:28 PM 4/19/2004, Deepa Manchepalli wrote:

I have an XML configuration file with multiple appenders. Each of the
appender has a variable associated with it.



I realize that all the variables have to be set before calling the
DOMConfigurator. Without initializing all the variables, I get the following
error.


log4j:ERROR setFile(null,false) call failed. java.io.FileNotFoundException: (No such file or directory) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:179) at java.io.FileOutputStream.<init>(FileOutputStream.java:102) at org.apache.log4j.FileAppender.setFile(FileAppender.java:272) at

This is not viable in my case, since, different programs use the same
configuration file to dynamically set the file name at *different* times.
For eg, when prg1 initializes and starts logging, appender_01 variable is
set and since prg 2 which uses appender_02 has not yet started the variable
2 is not yet initialized.

What's a way around this issue using a single configuration file?

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
  <appender name="appender_01" class="org.apache.log4j.FileAppender">
    <param name="File" value="${TaskServer.log}"/>
    <param name="Append" value="false"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="[%p] %r %C %d{ISO8601} %l %m
%n"/>
    </layout>
  </appender>

  <appender name="="appender_02" class="org.apache.log4j.FileAppender">
     <param name="File" value="${TaskServerHelper.log}"/>
     <param name="Append" value="false"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="[%p] %r %C %d{ISO8601} %l %m
%n"/>
    </layout>
  </appender>

<logger name="logger1">
   <appender-ref ref=" appender_01"/>
</logger>

<logger name="logger2">
   <appender-ref ref=" appender_02"/>
</logger>

</log4j:configuration>

Thanks,

Deepa.

-- Ceki Gülcü

For log4j documentation consider "The complete log4j manual"
ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to