This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How Can I log my pintStackTrace () statement into log file?

 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have log4j.xml file with different levels like debug and error, when run the application i can see logs of debug, info, error, etc.. in one log file.

how can i separate error messages to another file?

How Can I log my pintStackTrace () statement into log file?

if i use e.printStackTrace() in java catch block, then I can see exception in console only, but I want to see it in log file.

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How Can I log my pintStackTrace () statement into log file?
if i use e.printStackTrace() in java catch block, then I can see exception in console only, but I want to see it in log file.


The Logger has APIs which accept the exception object. The stacktrace will then be logged in the log file. See this and similar APIs
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Pai,

I followed the same thing, but I can's see the stack trace in log file, I just got exception only.

One more question. how can we separate error logs from general logs? i.e. I want to see errors in errorlog file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic