Commit 92f1a93b authored by 4Benj_'s avatar 4Benj_ Committed by GitHub
Browse files

Server Log Events (#996)

* Server Log Event

* LogEventAppender Encoder
parent 9125bacf
package emu.grasscutter.server.event.internal;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import emu.grasscutter.server.event.types.ServerEvent;
public class ServerLogEvent extends ServerEvent {
ILoggingEvent loggingEvent;
String consoleMessage;
public ServerLogEvent(Type type, ILoggingEvent loggingEvent, String consoleMessage) {
super(type);
this.loggingEvent = loggingEvent;
this.consoleMessage = consoleMessage;
}
public ILoggingEvent getLoggingEvent() { return loggingEvent; }
public String getConsoleMessage() {
return consoleMessage;
}
}
package emu.grasscutter.utils;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.encoder.Encoder;
import ch.qos.logback.core.spi.DeferredProcessingAware;
import ch.qos.logback.core.status.ErrorStatus;
import emu.grasscutter.server.event.internal.ServerLogEvent;
import emu.grasscutter.server.event.types.ServerEvent;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class ServerLogEventAppender<E> extends AppenderBase<E> {
protected Encoder<E> encoder;
@Override
protected void append(E event) {
byte[] byteArray = this.encoder.encode(event);
ServerLogEvent sle = new ServerLogEvent(ServerEvent.Type.GAME, (ILoggingEvent) event, new String(byteArray, StandardCharsets.UTF_8));
sle.call();
}
public Encoder<E> getEncoder() {
return encoder;
}
public void setEncoder(Encoder<E> encoder) {
this.encoder = encoder;
}
}
......@@ -16,6 +16,11 @@
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss'Z'} &lt;%level:%class&gt; %m%n</pattern>
</encoder>
</appender>
<appender name="SERVEREVENT" class="emu.grasscutter.utils.ServerLogEventAppender">
<encoder>
<pattern>%d{HH:mm:ss} &lt;%highlight(%level):%gray(%class{0})&gt; %msg%n</pattern>
</encoder>
</appender>
<logger name="org.reflections" level="OFF" />
<logger name="emu.grasscutter" level="${LOG_LEVEL}" />
......@@ -23,5 +28,6 @@
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
<appender-ref ref="SERVEREVENT" />
</root>
</Configuration>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment