Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
92f1a93b
Commit
92f1a93b
authored
May 20, 2022
by
4Benj_
Committed by
GitHub
May 20, 2022
Browse files
Server Log Events (#996)
* Server Log Event * LogEventAppender Encoder
parent
9125bacf
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/server/event/internal/ServerLogEvent.java
0 → 100644
View file @
92f1a93b
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
;
}
}
src/main/java/emu/grasscutter/utils/ServerLogEventAppender.java
0 → 100644
View file @
92f1a93b
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
;
}
}
src/main/resources/logback.xml
View file @
92f1a93b
...
@@ -16,6 +16,11 @@
...
@@ -16,6 +16,11 @@
<pattern>
%d{yyyy-MM-dd'T'HH:mm:ss'Z'}
<
%level:%class
>
%m%n
</pattern>
<pattern>
%d{yyyy-MM-dd'T'HH:mm:ss'Z'}
<
%level:%class
>
%m%n
</pattern>
</encoder>
</encoder>
</appender>
</appender>
<appender
name=
"SERVEREVENT"
class=
"emu.grasscutter.utils.ServerLogEventAppender"
>
<encoder>
<pattern>
%d{HH:mm:ss}
<
%highlight(%level):%gray(%class{0})
>
%msg%n
</pattern>
</encoder>
</appender>
<logger
name=
"org.reflections"
level=
"OFF"
/>
<logger
name=
"org.reflections"
level=
"OFF"
/>
<logger
name=
"emu.grasscutter"
level=
"${LOG_LEVEL}"
/>
<logger
name=
"emu.grasscutter"
level=
"${LOG_LEVEL}"
/>
...
@@ -23,5 +28,6 @@
...
@@ -23,5 +28,6 @@
<root
level=
"INFO"
>
<root
level=
"INFO"
>
<appender-ref
ref=
"STDOUT"
/>
<appender-ref
ref=
"STDOUT"
/>
<appender-ref
ref=
"FILE"
/>
<appender-ref
ref=
"FILE"
/>
<appender-ref
ref=
"SERVEREVENT"
/>
</root>
</root>
</Configuration>
</Configuration>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment