Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback - custom output for exceptions

I have some specific problem with logback. We've migrated from log4j to logback and all seems to be alright, but we have an exception class MultiCauseException. As you guessed - it can have more than one cause exception, so the problem is: I can't manually format stacktrace to see all causes.

Why it was working. Log4j used method printStackTrace() and you can override it in MultiCauseException and the problem is gone. But logback uses his own methods and I don't know how to replace them.

I want to log all causes correctly.

In class I have

MultiCauseException nextInChain; // my cause
Throwable inner; 
        // the real exception (inner.getCause() can be != null - must be logged)

And

 @Override
    public Throwable getCause() {
        return nextInChain;
    }
like image 913
Edd Avatar asked Nov 13 '22 20:11

Edd


1 Answers

Logback has something called Layouts that is suppoesed to format events to strings . But I still believe you should be able to configure it with PatternLayout

like image 138
Suraj Chandran Avatar answered Nov 15 '22 10:11

Suraj Chandran