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 org.apache.logging.log4j.Level;
20 import org.apache.logging.log4j.Marker;
21 import org.apache.logging.log4j.ThreadContext.ContextStack;
22 import org.apache.logging.log4j.core.ContextDataInjector;
23 import org.apache.logging.log4j.core.impl.ContextDataInjectorFactory;
24 import org.apache.logging.log4j.util.StringMap;
25 import org.apache.logging.log4j.message.Message;
26
27 import com.lmax.disruptor.EventTranslator;
28
29
30
31
32
33
34
35 public class RingBufferLogEventTranslator implements
36 EventTranslator<RingBufferLogEvent> {
37
38 private final ContextDataInjector injector = ContextDataInjectorFactory.createInjector();
39 private AsyncLogger asyncLogger;
40 String loggerName;
41 protected Marker marker;
42 protected String fqcn;
43 protected Level level;
44 protected Message message;
45 protected Throwable thrown;
46 private ContextStack contextStack;
47 private long threadId = Thread.currentThread().getId();
48 private String threadName = Thread.currentThread().getName();
49 private int threadPriority = Thread.currentThread().getPriority();
50 private StackTraceElement location;
51 private long currentTimeMillis;
52 private long nanoTime;
53
54
55 @Override
56 public void translateTo(final RingBufferLogEvent event, final long sequence) {
57
58 event.setValues(asyncLogger, loggerName, marker, fqcn, level, message, thrown,
59
60
61 injector.injectContextData(null, (StringMap) event.getContextData()), contextStack,
62 threadId, threadName, threadPriority, location, currentTimeMillis, nanoTime);
63
64 clear();
65 }
66
67
68
69
70 private void clear() {
71 setBasicValues(null,
72 null,
73 null,
74 null,
75 null,
76 null,
77 null,
78 null,
79 null,
80 0,
81 0
82 );
83 }
84
85 public void setBasicValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
86 final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable,
87 final ContextStack aContextStack, final StackTraceElement aLocation,
88 final long aCurrentTimeMillis, final long aNanoTime) {
89 this.asyncLogger = anAsyncLogger;
90 this.loggerName = aLoggerName;
91 this.marker = aMarker;
92 this.fqcn = theFqcn;
93 this.level = aLevel;
94 this.message = msg;
95 this.thrown = aThrowable;
96 this.contextStack = aContextStack;
97 this.location = aLocation;
98 this.currentTimeMillis = aCurrentTimeMillis;
99 this.nanoTime = aNanoTime;
100 }
101
102 public void updateThreadValues() {
103 final Thread currentThread = Thread.currentThread();
104 this.threadId = currentThread.getId();
105 this.threadName = currentThread.getName();
106 this.threadPriority = currentThread.getPriority();
107 }
108 }