All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.pythagoras.common.grayloglogger.ConsoleAppenderWrapper Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy