logging - log4j2 specify relative path to tomcat home dir for FileAppender -


i trying configure log4j2 tomcat server running locally. unable pipe logs location relative tomcat install.

if specify absolute path works. if use relative path outputs location of system.getproperty("user.dir").

but when try use either ${catalina.home} or ${catalina.base} not work. if output 2 system properties on startup, defined , point proper location.

also,

  • tomcat 7.0.26
  • servlet 2.5
  • log4j2.0 beta 8
  • we using slf4j log4j2 behind it.
  • i setup loggers async through environment variable -dlog4jcontextselector=org.apache.logging.log4j.core.async.asyncloggercontextselector.

my feeling tomcat might not initialized when processes log4j2.xml? ideas appreciated!

here log4j2.xml:

<?xml version="1.0" encoding="utf-8"?> <configuration status="debug" name="loggingconfig">    <appenders>     <fastfile name="alog" filename="${catalina.home}/logs/test.log" immediateflush="true" append="true">       <patternlayout>         <pattern>%d %p %c{1.} [%t] %m%n</pattern>       </patternlayout>     </fastfile>   </appenders>    <loggers>     <logger name="a.namespace.dir" level="info" additivity="false">       <appender-ref ref="alog"/>     </logger>      <root level="info">       <appender-ref ref="alog"/>     </root>   </loggers>  </configuration> 

from catalina.out

2013-07-31 11:22:00,313 debug calling createappender on class org.apache.logging.log4j.core.appender.fastfileappender element fastfile params(filename="${catalina.home}/logs/test.log", append="true", name="alog", immediateflush="true", suppressexceptions="null", patternlayout(%d %p %c{1.} [%t] %m%n), null, advertise="null", advertiseuri="null", configuration(loggingconfig))  2013-07-31 11:22:00,315 debug starting fastfilemanager ${catalina.home}/logs/test.log  2013-07-31 11:22:00,316 debug calling createappenders on class org.apache.logging.log4j.core.config.plugins.appendersplugin element appenders params(appenders={alog})  2013-07-31 11:22:00,317 debug generated plugins in 0.000016000 seconds  2013-07-31 11:22:00,318 debug calling createappenderref on class org.apache.logging.log4j.core.config.appenderref element appender-ref params(ref="alog", level="null", null)  2013-07-31 11:22:00,320 debug calling createlogger on class org.apache.logging.log4j.core.config.loggerconfig element logger params(additivity="false", level="info", name="a.namespace.dir", includelocation="null", appender-ref={org.apache.logging.log4j.core.config.appenderref@6e8ef177}, properties={}, configuration(loggingconfig), null)  2013-07-31 11:22:00,321 debug calling createappenderref on class org.apache.logging.log4j.core.config.appenderref element appender-ref params(ref="alog", level="null", null)  2013-07-31 11:22:00,322 debug calling createlogger on class org.apache.logging.log4j.core.config.loggerconfig$rootlogger element root params(additivity="null", level="info", includelocation="null", appender-ref={org.apache.logging.log4j.core.config.appenderref@6a8ef455}, properties={}, configuration(loggingconfig), null)  2013-07-31 11:22:00,323 debug calling createloggers on class org.apache.logging.log4j.core.config.plugins.loggersplugin element loggers params(loggers={a.namespace.dir, root}) 

i solved own issue. system properties need prefix variables sys:.

<fastfile name="alog" filename="${sys:catalina.home}/logs/test.log" immediateflush="true" append="true">   <patternlayout>     <pattern>%d %p %c{1.} [%t] %m%n</pattern>   </patternlayout> </fastfile> 

found after re-reading part of documentation: http://logging.apache.org/log4j/2.x/manual/configuration.html#propertysubstitution


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -