0

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 2

0

Try passing additional parameter with log4j config file path:

-Dlog4j.configuration={path to file} 

how-do-i-set-log4j-level-on-the-command-line

log4j-configuration-via-jvm-arguments

Sign up to request clarification or add additional context in comments.

4 Comments

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.
So how are you invoking this app form shell script? Something like this: java -jar <file_name>.jar?
export CLASSPATH=...all my jars including project.jar-Dlog4j.configuration={path to file} java -cp ${CLASSPATH} com.pack.StartPoint checkStatus
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
0

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

I have WEB-INF/lib/log4j-1.2.8.jar in my classpath is this enough?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.