I have a log4j.properties file
log4j.appender.BigBrotherLog=org.apache.log4j.RollingFileAppender
log4j.appender.BigBrotherLog.File=${userprofile.broker.bigbrother.log4j.file.path}
log4j.appender.BigBrotherLog.MaxFileSize=100MB
log4j.appender.BigBrotherLog.MaxBackupIndex=10
log4j.appender.BigBrotherLog.layout=org.apache.log4j.PatternLayout
log4j.appender.BigBrotherLog.layout.ConversionPattern=%d{yy/MM/dd} %d{HH:mm:ss} ALARM CRITICAL SITA ESB (SOAESB) [%-t] (%F:%L) %-5p %-c{1} %x- %m%n
log4j.appender.BigBrotherLog.Threshold=FATAL
where I'm passing ${userprofile.broker.bigbrother.log4j.file.path} from a external properties file. But I want to have put this external properties file in the class path. How can I make it work? Thanks.
The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.
It's optional if the file name is log4j. properties and it's in the project classpath. We have to configure it before using the logger. Here is a simple program showing how to configure and use log4j logging.
Add log4j jar file to classpath of the project. In the Java Build Path dialogue, go to Libraries tab and Click on Add External JARs button and add the log4j-xxx. jar file by browsing your local drive where log4j jar file is extracted and Click OK. Now the log4j jar file is available to be used in your application.
When you invoke the java command, pass in the system property -Dlog4j.configuration=file:[path-to-your-external-file]
. The important part is the file:
, otherwise log4j will only attempt to load from the class path and system resources.
You can also use -Dlog4j.debug=true
to see where log4j has attempted to source it's configuration file from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With