provide framework for application logging

This commit is contained in:
Craig Raw 2021-03-08 09:16:28 +02:00
parent c084a0de7e
commit 5b2e21b3d7
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,20 @@
package com.sparrowwallet.drongo;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import org.slf4j.event.Level;
import java.lang.reflect.InvocationTargetException;
public class ApplicationAppender extends AppenderBase<ILoggingEvent> {
private LogHandler callback;
@Override
protected void append(ILoggingEvent e) {
callback.handleLog(e.getThreadName(), Level.valueOf(e.getLevel().toString()), e.getMessage(), e.getLoggerName(), e.getTimeStamp(), e.getCallerData());
}
public void setCallback(String callback) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
this.callback = (LogHandler)Class.forName(callback).getConstructor().newInstance();
}
}

View file

@ -0,0 +1,7 @@
package com.sparrowwallet.drongo;
import org.slf4j.event.Level;
public interface LogHandler {
void handleLog(String threadName, Level level, String message, String loggerName, long timestamp, StackTraceElement[] callerData);
}