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 protected Marker marker;
40 protected String fqcn;
41 protected Level level;
42 protected Message message;
43 protected Throwable thrown;
44 private Map<String, String> contextMap;
45 private ContextStack contextStack;
46 private long threadId = Thread.currentThread().getId();
47 private String threadName = Thread.currentThread().getName();
48 private int threadPriority = Thread.currentThread().getPriority();
49 private StackTraceElement location;
50 private long currentTimeMillis;
51 private long nanoTime;
52
53
54 @Override
55 public void translateTo(final RingBufferLogEvent event, final long sequence) {
56 event.setValues(asyncLogger, loggerName, marker, fqcn, level, message, thrown, contextMap, contextStack,
57 threadId, threadName, threadPriority, location, currentTimeMillis, nanoTime);
58 clear();
59 }
60
61
62
63
64 private void clear() {
65 setBasicValues(null,
66 null,
67 null,
68 null,
69 null,
70 null,
71 null,
72 null,
73 null,
74 null,
75 0,
76 0
77 );
78 }
79
80 public void setBasicValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
81 final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable,
82 final Map<String, String> aMap, final ContextStack aContextStack, final StackTraceElement aLocation,
83 final long aCurrentTimeMillis, final long aNanoTime) {
84 this.asyncLogger = anAsyncLogger;
85 this.loggerName = aLoggerName;
86 this.marker = aMarker;
87 this.fqcn = theFqcn;
88 this.level = aLevel;
89 this.message = msg;
90 this.thrown = aThrowable;
91 this.contextMap = aMap;
92 this.contextStack = aContextStack;
93 this.location = aLocation;
94 this.currentTimeMillis = aCurrentTimeMillis;
95 this.nanoTime = aNanoTime;
96 }
97
98 public void updateThreadValues() {
99 final Thread currentThread = Thread.currentThread();
100 this.threadId = currentThread.getId();
101 this.threadName = currentThread.getName();
102 this.threadPriority = currentThread.getPriority();
103 }
104 }