logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Camer38 <rembi...@gmail.com>
Subject log4j 1.2.15 DOMConfigurator.subst
Date Fri, 09 Apr 2010 08:43:28 GMT

Any chance for a help or at lease link to working example of
DOMConfigurator.subst




I try to use DOMConfigurator.subst to change dynamically in Java code
location of the output logging file. See log4j.xml below.

The following code is called in main method to set up file location:

    private static void setLogging(final String logDirectory, final String
logFileName) {
        Properties props = new Properties();
        props.put("dir.log", logDirectory);
        props.put("file.name", logFileName);
        String s3 = DOMConfigurator.subst("${dir.log}", props);
        String s4 = DOMConfigurator.subst("${file.name}", props);
    }

It does not work for me because I get following error:

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: \ (The system cannot find the path specified)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at
org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:194)
    at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:164)
    at
org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:257)
    at
org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:285)
    at
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:171)
    at
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:184)
    at
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:502)
    at
org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:471)
    at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:921)
    at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:790)
    at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:696)
    at
org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
    at org.apache.log4j.Logger.getLogger(Logger.java:118)
    at
curam.tools.upgradehelper.SampleJavaSourceMigrationTool.<clinit>(SampleJavaSourceMigrationTool.java:36)

Could you give me a tip what am I missing, please?

Marcin

log4j.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration
  debug="null"
  xmlns:log4j="http://jakarta.apache.org/log4j/"
  threshold="null"
>

  <appender
    class="org.apache.log4j.RollingFileAppender"
    name="LogFileAppender"
  >
    
    
    
    
    <layout class="org.apache.log4j.PatternLayout">
      
    </layout>
  </appender>

  <!-- Loggers  -->
  <root>
    <level value="DEBUG"/>
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="LogFileAppender"/>
  </root>
</log4j:configuration>
-- 
View this message in context: http://old.nabble.com/log4j-1.2.15-DOMConfigurator.subst-tp28189312p28189312.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message