mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +00:00
provide framework for application logging
This commit is contained in:
parent
c084a0de7e
commit
5b2e21b3d7
2 changed files with 27 additions and 0 deletions
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
7
src/main/java/com/sparrowwallet/drongo/LogHandler.java
Normal file
7
src/main/java/com/sparrowwallet/drongo/LogHandler.java
Normal 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);
|
||||||
|
}
|
Loading…
Reference in a new issue