• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception stack trace not going to log file

 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pls paste here more of your log4j.properties file. Have you configured the consolePrinter and ROOT appenders? What priorities?

--
./pope
[the_mindstorm]
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to change ERROR to be DEBUG priority, does it write exception stacktrace?
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have log4j.debug = true, but it did not help me.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, what version of log4j are you using?
 
emm raha
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're catching 'ex' and sending 'e' to your logger. I tried your log4j.properties with this, and it works fine:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic