Reputation: 335
I have made a project in which I am creating logs with log4j2.xml. My configuration file works perfectly when I am running it in the eclipse of my windows system. Here is the configuration file which I have used to create the log files.
<?xml version="1.0" encoding="UTF-8" standalone="no"?><Configuration status="WARN">
<Properties>
<Property name="log-path">/home/apps/ora_fin/IGL75D/Disco/splunk/log</Property>
</Properties>
<Appenders>
<RollingFile fileName="${log-path}/SplunkOADC.log" filePattern="${log-path}/SplunkOADC-%d{yyyy-MM-dd}.log" name="info-log">
<Filters>
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<PatternLayout>
<pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<RollingFile fileName="${log-path}/SplunkOADC-trace.log" filePattern="${log-path}/SplunkOADC-trace-%d{yyyy-MM-dd}.log" name="trace-log">
<Filters>
<ThresholdFilter level="info" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="fatal" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
<ThresholdFilter level="TRACE" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
<ThresholdFilter level="FATAL" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="1 MB"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger level="all" name="com.aviva.uk.gi.NUProcessOSBReportDataParserPkg">
<AppenderRef ref="info-log"/>
<AppenderRef ref="trace-log"/>
</Logger>
<Root>
</Root>
</Loggers>
</Configuration>
This configuration file I have put under the src folder in my project and is picked up without any issues. However I need to deploy the application in the Unix environment, where should I put the configuration file in unix environment so that it is picked up by the java class to log ??
Thanks!
Upvotes: 1
Views: 2042
Reputation: 36834
The simplest thing to do is to just add the config file to the classpath of your application.
For a web app that means putting it in WEB-INF/classes/
.
Alternatively you can use the system property suggested in the other answer.
Upvotes: 1
Reputation: 6190
How about using a jvm argument always
-Dlog4j.configuration={path to file}
This should work irrespective of the environment you deploy in.
Upvotes: 1