Redirect stack trace to a string

Discussion in 'Java' started by Sylvain, Mar 5, 2008.

  1. Sylvain

    Sylvain Guest

    Hi !

    I would like to be able to log for an exception, not only the e.getMessage()
    but the whole e.printStackTrace(). Does anybody know how to redirect
    temporarily the standard out to a string ?

    Ideal would be such a function :
    - store the standard out
    - change the standard out to a string reader
    - execute the e.printStackTrace()
    - log the output string
    - restore the standard out

    Thank you for your help

    Best regards

    Sylvain Caillet
     
    Sylvain, Mar 5, 2008
    #1
    1. Advertising

  2. Sylvain wrote:
    > Hi !
    >
    > I would like to be able to log for an exception, not only the e.getMessage()
    > but the whole e.printStackTrace(). Does anybody know how to redirect
    > temporarily the standard out to a string ?
    >
    > Ideal would be such a function :
    > - store the standard out
    > - change the standard out to a string reader
    > - execute the e.printStackTrace()
    > - log the output string
    > - restore the standard out
    >
    > Thank you for your help
    >
    > Best regards
    >
    > Sylvain Caillet
    >
    >


    Use printStackTrace(PrintWriter w) ?
     
    Silvio Bierman, Mar 5, 2008
    #2
    1. Advertising

  3. Sylvain

    Real Gagnon Guest

    > I would like to be able to log for an exception, not only the
    > e.getMessage() but the whole e.printStackTrace(). Does anybody know
    > how to redirect temporarily the standard out to a string ?


    You don't need to do that. Just attach a StringWriter to a PrintWriter and
    use the appropriate e.printStackTrace().

    Example at http://www.rgagnon.com/javadetails/java-0029.html

    Bye.
    --
    Real Gagnon from Quebec, Canada
    * Java, Javascript, VBScript and PowerBuilder code snippets
    * http://www.rgagnon.com/howto.html
    * http://www.rgagnon.com/bigindex.html
     
    Real Gagnon, Mar 5, 2008
    #3
  4. Sylvain

    Sylvain Guest

    thank you. It works fine.
    Sylvain

    "Real Gagnon" <> a écrit dans le message de
    news: Xns9A588E6FAC430realhowtowwwrgagnonc@140.99.99.130...
    >> I would like to be able to log for an exception, not only the
    >> e.getMessage() but the whole e.printStackTrace(). Does anybody know
    >> how to redirect temporarily the standard out to a string ?

    >
    > You don't need to do that. Just attach a StringWriter to a PrintWriter and
    > use the appropriate e.printStackTrace().
    >
    > Example at http://www.rgagnon.com/javadetails/java-0029.html
    >
    > Bye.
    > --
    > Real Gagnon from Quebec, Canada
    > * Java, Javascript, VBScript and PowerBuilder code snippets
    > * http://www.rgagnon.com/howto.html
    > * http://www.rgagnon.com/bigindex.html
     
    Sylvain, Mar 6, 2008
    #4
  5. Sylvain

    Sylvain Guest

    Thank you.
    Sylvain

    "Silvio Bierman" <> a écrit dans le message de
    news: 47ce848b$0$14350$4all.nl...
    > Sylvain wrote:
    >> Hi !
    >>
    >> I would like to be able to log for an exception, not only the
    >> e.getMessage() but the whole e.printStackTrace(). Does anybody know how
    >> to redirect temporarily the standard out to a string ?
    >>
    >> Ideal would be such a function :
    >> - store the standard out
    >> - change the standard out to a string reader
    >> - execute the e.printStackTrace()
    >> - log the output string
    >> - restore the standard out
    >>
    >> Thank you for your help
    >>
    >> Best regards
    >>
    >> Sylvain Caillet

    >
    > Use printStackTrace(PrintWriter w) ?
     
    Sylvain, Mar 6, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rukmal Fernando
    Replies:
    4
    Views:
    864
    Richard Grimes [MVP]
    Oct 27, 2003
  2. Matthias S.
    Replies:
    1
    Views:
    668
    Daniel Fisher\(lennybacon\)
    Nov 30, 2005
  3. Jiho Han
    Replies:
    0
    Views:
    535
    Jiho Han
    Aug 22, 2006
  4. =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    Adding my messages to the trace.axd trace?

    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=, Apr 6, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    604
    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
    Apr 6, 2007
  5. Chris Newby
    Replies:
    0
    Views:
    778
    Chris Newby
    Jul 28, 2008
Loading...

Share This Page