• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting PrintStream or PrintWriter from logger

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am catching exception and want to log these too. (->printStackTrace(PrintStream or PrintWriter) ), i need a way to retrieve
a PrintStream or PrintWriter of my logger.

is that possible?

otherwise i would need to build a utility method to log exceptions by using Logger.getStackTrace()...

thanks.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this of some help:
Convert Exception Stacktrace to String
Once the exception stacktrace is converted to string, you can log the same as follows:


[ September 12, 2006: Message edited by: jaikiran pai ]
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks,

i know that you can transform an exception stack trace to a string, but it requires another helper method, which i wanted to avoid.

so there is no possibility to get an ouput stream (which is i think an obvious logging framework requirement) from log4j?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as i know, there isnt an API in log4j to obtain the PrintStream. Here's one thread, from the log4j archives, which talks about the same:

Can i get PrintStream from Log4j
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All of the logging methods in log4j (info, error, and so on) have overloaded versions that accept an Exception parameter. What's wrong with using those methods?
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh yes,

i must have been blind... in the first place i only tried to use following which just showed me the expception but not the stack trace:
...
catch(Exception e){
logger.error(e);
}

but there is a overloaded logger method error(Object,Exception) too
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic