File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed
wrappercommon/src/main/java/com/genexus/diagnostics/core/provider Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .genexus .diagnostics .core .provider ;
2+
3+ import org .apache .logging .log4j .core .config .plugins .Plugin ;
4+ import org .apache .logging .log4j .core .config .plugins .PluginFactory ;
5+ import org .apache .logging .log4j .layout .template .json .resolver .EventResolverContext ;
6+ import org .apache .logging .log4j .layout .template .json .resolver .EventResolverFactory ;
7+ import org .apache .logging .log4j .layout .template .json .resolver .TemplateResolverConfig ;
8+ import org .apache .logging .log4j .layout .template .json .resolver .TemplateResolverFactory ;
9+
10+
11+ @ Plugin (name = "CustomMessageFactory" , category = TemplateResolverFactory .CATEGORY )
12+ public final class CustomMessageFactory implements EventResolverFactory {
13+ private static final CustomMessageFactory INSTANCE = new CustomMessageFactory ();
14+
15+ @ PluginFactory
16+ public static CustomMessageFactory getInstance () {
17+ return INSTANCE ;
18+ }
19+
20+ @ Override
21+ public String getName () {
22+ return CustomMessageResolver .getName ();
23+ }
24+
25+ @ Override
26+ public CustomMessageResolver create (EventResolverContext context , TemplateResolverConfig config ) {
27+ return new CustomMessageResolver (config );
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ package com .genexus .diagnostics .core .provider ;
2+
3+ import org .apache .logging .log4j .core .LogEvent ;
4+ import org .apache .logging .log4j .layout .template .json .resolver .EventResolver ;
5+ import org .apache .logging .log4j .layout .template .json .resolver .TemplateResolverConfig ;
6+ import org .apache .logging .log4j .layout .template .json .util .JsonWriter ;
7+ import org .apache .logging .log4j .message .MapMessage ;
8+ import org .apache .logging .log4j .message .Message ;
9+
10+
11+ public class CustomMessageResolver implements EventResolver {
12+ private static final String RESOLVER_NAME = "customMessage" ;
13+
14+ CustomMessageResolver (TemplateResolverConfig config ) {
15+ }
16+
17+ static String getName () {
18+ return RESOLVER_NAME ;
19+ }
20+
21+ @ Override
22+ public void resolve (LogEvent logEvent , JsonWriter jsonWriter ) {
23+ Message message = logEvent .getMessage ();
24+ if (message instanceof MapMessage ) {
25+ MapMessage <?, ?> mapMessage = (MapMessage <?, ?>) message ;
26+ Object msgValue = mapMessage .get ("message" );
27+ if (msgValue != null ) {
28+ jsonWriter .writeString (msgValue .toString ());
29+ return ;
30+ }
31+ }
32+ // fallback
33+ jsonWriter .writeString (message .getFormattedMessage ());
34+ }
35+ }
36+
You can’t perform that action at this time.
0 commit comments