io.pythagoras.common.grayloglogger.ConsoleAppenderWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graylog-logger Show documentation
Show all versions of graylog-logger Show documentation
Pythagoras Common Libs - Graylog Logger
package io.pythagoras.common.grayloglogger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.spi.ThrowableProxy;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.ConsoleAppender;
import io.pythagoras.common.loggercommon.LogObject;
import org.springframework.stereotype.Service;
@Service
public class ConsoleAppenderWrapper extends AppenderBase {
private ConsoleAppender consoleAppender;
public void setConsoleAppender(ConsoleAppender consoleAppender) {
this.consoleAppender = consoleAppender;
}
@Override
protected void append(ILoggingEvent iLoggingEvent) {
if (iLoggingEvent instanceof ch.qos.logback.classic.spi.LoggingEvent) {
Object[] args = iLoggingEvent.getArgumentArray();
if (args != null && args.length > 0) {
Object obj = iLoggingEvent.getArgumentArray()[0];
if (obj instanceof LogObject) {
// We have a logged error. Lets unwrap it.
((LoggingEvent) iLoggingEvent).setThrowableProxy(new ThrowableProxy(((LogObject) obj).exception));
}
}
this.consoleAppender.doAppend(iLoggingEvent);
}
}
}