| Author |
exception stack trace not going to log file
|
Santosh Ramachandrula
Ranch Hand
Joined: Apr 04, 2004
Posts: 251
|
|
Folks, I am using log4j in my application and I am trying to send all the exception stack traces to a log file. I have set the logger priority to ERROR in log4j.properties log4j.rootCategory=ERROR, consolePrinter, ROOT In the my java class I am using the following statement to write the stack trace to the log file but it does'nt work. try{ //code here }catch(Exception ex){ logger.error( "Class.Exception",e); } Any suggestions/ideas? Thanks for the help in advance guys...
|
Thanks,
Santosh
|
 |
Alexandru Popescu
Ranch Hand
Joined: Jul 12, 2004
Posts: 995
|
|
Pls paste here more of your log4j.properties file. Have you configured the consolePrinter and ROOT appenders? What priorities? -- ./pope [the_mindstorm]
|
blog - InfoQ.com
|
 |
Santosh Ramachandrula
Ranch Hand
Joined: Apr 04, 2004
Posts: 251
|
|
Ali Pope, Thanks for the reply and here are the contents of log4j.properties file ############### Following are my settings ############ #Default log level to ERROR. Other levels are INFO and DEBUG. #log4j.rootLogger=DEBUG, ROOT #log4j.rootCategory=DEBUG, consolePrinter, ROOT log4j.rootCategory=ERROR, consolePrinter, ROOT #### This appender writes to console ############## log4j.appender.consolePrinter=org.apache.log4j.ConsoleAppender log4j.appender.consolePrinter.layout=org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number. log4j.appender.consolePrinter.layout.ConversionPattern=%n%m%n #### End of appender writing to console ############## log4j.appender.ROOT=org.apache.log4j.RollingFileAppender #log4j.appender.ROOT=org.apache.log4j.ConsoleAppender log4j.appender.ROOT.File=c:/temp/tcc.log log4j.appender.ROOT.MaxFileSize=1000KB #Keep 5 old files around. log4j.appender.ROOT.MaxBackupIndex=5 log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout #Format almost same as WebSphere's common log format. log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %c %-5p - %m%n #Optionally override log level of individual packages or classes log4j.logger.com.webage.ejbs=INFO
|
 |
Alexandru Popescu
Ranch Hand
Joined: Jul 12, 2004
Posts: 995
|
|
Santosh, unfortunatelly everything seems oke with me :-(. Just one more thing: are you sure it is in your classpath? -- ./pope [the_mindstorm]
|
 |
Santosh Ramachandrula
Ranch Hand
Joined: Apr 04, 2004
Posts: 251
|
|
Yes it is in classpath, I can get the message with ERROR priority like log.error("some message"); to the log file but for some reason(s) I am not able to send the stack trace message to the log file if an exception occurs. I am using log.error("XXXException", ex); to send the stack trace to the log file.
|
 |
Siripa Siangklom
Ranch Hand
Joined: Jan 26, 2004
Posts: 79
|
|
|
Try to change ERROR to be DEBUG priority, does it write exception stacktrace?
|
 |
Santosh Ramachandrula
Ranch Hand
Joined: Apr 04, 2004
Posts: 251
|
|
Siripa, Thanks for the response. I tried DEBUG and ERROR priorities. They both work for normal messages but not for stack trace.
|
 |
Carol Enderlin
drifter
Ranch Hand
Joined: Oct 10, 2000
Posts: 1340
|
|
Did you try turning on log4j debug? log4j.debug=true in config file or -Dlog4j.debug on the command line. What version of log4j are you using? If you're using the 1.3 alpha version that could be the problem.
|
 |
Santosh Ramachandrula
Ranch Hand
Joined: Apr 04, 2004
Posts: 251
|
|
|
I have log4j.debug = true, but it did not help me.
|
 |
Carol Enderlin
drifter
Ranch Hand
Joined: Oct 10, 2000
Posts: 1340
|
|
|
OK, what version of log4j are you using?
|
 |
emm raha
Ranch Hand
Joined: Mar 18, 2003
Posts: 57
|
|
You're catching 'ex' and sending 'e' to your logger. I tried your log4j.properties with this, and it works fine:
|
 |
 |
|
|
subject: exception stack trace not going to log file
|
|
|