1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.async;
18
19 import java.util.Map;
20
21 import org.apache.logging.log4j.Level;
22 import org.apache.logging.log4j.Marker;
23 import org.apache.logging.log4j.ThreadContext.ContextStack;
24 import org.apache.logging.log4j.message.Message;
25
26 import com.lmax.disruptor.EventTranslator;
27
28
29
30
31
32
33
34 public class RingBufferLogEventTranslator implements
35 EventTranslator<RingBufferLogEvent> {
36
37 private AsyncLogger asyncLogger;
38 private String loggerName;
39 private Marker marker;
40 private String fqcn;
41 private Level level;
42 private Message message;
43 private Throwable thrown;
44 private Map<String, String> contextMap;
45 private ContextStack contextStack;
46 private String threadName;
47 private StackTraceElement location;
48 private long currentTimeMillis;
49 private long nanoTime;
50
51
52 @Override
53 public void translateTo(final RingBufferLogEvent event, final long sequence) {
54 event.setValues(asyncLogger, loggerName, marker, fqcn, level, message,
55 thrown, contextMap, contextStack, threadName, location,
56 currentTimeMillis, nanoTime);
57 clear();
58 }
59
60
61
62
63
64 private void clear() {
65 setValues(null,
66 null,
67 null,
68 null,
69 null,
70 null,
71 null,
72 null,
73 null,
74 null,
75 null,
76 0,
77 0
78 );
79 }
80
81 public void setValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
82 final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable,
83 final Map<String, String> aMap, final ContextStack aContextStack, final String aThreadName,
84 final StackTraceElement aLocation, final long aCurrentTimeMillis, final long aNanoTime) {
85 this.asyncLogger = anAsyncLogger;
86 this.loggerName = aLoggerName;
87 this.marker = aMarker;
88 this.fqcn = theFqcn;
89 this.level = aLevel;
90 this.message = msg;
91 this.thrown = aThrowable;
92 this.contextMap = aMap;
93 this.contextStack = aContextStack;
94 this.threadName = aThreadName;
95 this.location = aLocation;
96 this.currentTimeMillis = aCurrentTimeMillis;
97 this.nanoTime = aNanoTime;
98 }
99
100 public void setValuesPart1(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
101 final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable) {
102 this.asyncLogger = anAsyncLogger;
103 this.loggerName = aLoggerName;
104 this.marker = aMarker;
105 this.fqcn = theFqcn;
106 this.level = aLevel;
107 this.message = msg;
108 this.thrown = aThrowable;
109 }
110
111 public void setValuesPart2(final Map<String, String> aMap, final ContextStack aContextStack, final String aThreadName,
112 final StackTraceElement aLocation, final long aCurrentTimeMillis, final long aNanoTime) {
113 this.contextMap = aMap;
114 this.contextStack = aContextStack;
115 this.threadName = aThreadName;
116 this.location = aLocation;
117 this.currentTimeMillis = aCurrentTimeMillis;
118 this.nanoTime = aNanoTime;
119 }
120 }