0

I have this error stack trace method which sends to log4j error messages:

public void writeErrorStackMessage(String message)
    {
        log.error(message);
    }

I want also to add printing of stack trace into file.

catch (Exception e)
        {
            lm.writeErrorStackMessage(e.printStackTrace());
        }

The question is what is the proper way to send the error stack as message?

Edit:

public void writeErrorStackMessage(String message)
    {
        log.error(message);
    }


catch (Exception e)
        {
            lm.writeErrorStackMessage(Arrays.toString(e.getStackTrace()));
        }

I modified the code this way.

user1285928
  • 1,328
  • 29
  • 98
  • 147

1 Answers1

1

The e.printStackTrace() method also takes an PrintWriter or PrintStream argumument so if your lm object has an OutputStream you should be able to do

e.printStackTrace(new PrintStream (lm.getOutputStream ()));
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64