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?

keyanwb
  • 63
  • 1
  • 7

2 Answers2

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.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • I have WEB-INF/lib/log4j-1.2.8.jar in my classpath is this enough? – keyanwb Aug 08 '13 at 11:19
  • 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. – Juned Ahsan Aug 08 '13 at 17:53
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

Community
  • 1
  • 1
kaos
  • 1,598
  • 11
  • 15
  • 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. – keyanwb Aug 08 '13 at 11:31
  • So how are you invoking this app form shell script? Something like this: java -jar .jar? – kaos Aug 08 '13 at 11:46
  • export CLASSPATH=...all my jars including project.jar-Dlog4j.configuration={path to file} java -cp ${CLASSPATH} com.pack.StartPoint checkStatus – keyanwb Aug 08 '13 at 11:57
  • 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 – kaos Aug 08 '13 at 12:23