I am having a seperate jar file which do some stuffs. Which is actually deployed in tomcat. Inside that jar I have a java file with main method. Say the class name is StartPoint. I am calling that main method from a shell script by "java StartPoint checkStatus". The main method validates the checkStatus param and do the job accordingly. All java files inside the jar uses log4j and uses log.info/log.debug for logging. These logs are working fine if tomcat is up. Due to some requirement I triggered the main method from a shell script and now I am unable to get those log information. Please help how can I get the logs added using logger.info/debug?
2 Answers
Try passing additional parameter with log4j config file path:
-Dlog4j.configuration={path to file} 4 Comments
keyanwb
Hi this should be fine if I am acessing my application using tomcat. What I am using is a stand alone java program which is inside my project's jar. I am calling that particular file alone from shell script.
kaos
So how are you invoking this app form shell script? Something like this: java -jar <file_name>.jar?
keyanwb
export CLASSPATH=...all my jars including project.jar-Dlog4j.configuration={path to file} java -cp ${CLASSPATH} com.pack.StartPoint checkStatus
kaos
You have environment property in CLASSPATH: '-Dlog4j.configuration={path to file}'. I think it shuld be like this java -Dlog4j.configuration={path to file} -cp ${CLASSPATH} com.pack.StartPoint checkStatus
So I believe you just need to make sure that log4j.properties/log4j.xml is on the classpath when you call the StartPoint main method directly.
2 Comments
keyanwb
I have WEB-INF/lib/log4j-1.2.8.jar in my classpath is this enough?
Juned Ahsan
no just jar is not enough, basically log4j reads configuration such as where to put logs(console,file etc), file rolling, logs date format etc from log4j.properties/log4j.xml. You need to make sure that this config file is present in your classpath.