LogEntryImpl.java
4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* ch.qos.logback.classic.Level
* ch.qos.logback.classic.spi.ILoggingEvent
* ch.qos.logback.classic.spi.IThrowableProxy
* ch.qos.logback.classic.spi.StackTraceElementProxy
* ch.qos.logback.classic.spi.ThrowableProxyUtil
*/
package com.adobe.granite.logging.impl;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.StackTraceElementProxy;
import ch.qos.logback.classic.spi.ThrowableProxyUtil;
import com.adobe.granite.logging.LogEntry;
import com.adobe.granite.logging.LogLevel;
public class LogEntryImpl
implements LogEntry {
private final LogLevel level;
private final String exceptionOutput;
private final String message;
private final String name;
private final String threadName;
private final long timestamp;
private static final char TAB = '\t';
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
public LogEntryImpl(ILoggingEvent event, int maxSize) {
LogLevel localLevel;
String exception;
String l = event.getLevel().toString();
try {
localLevel = LogLevel.valueOf(l);
}
catch (IllegalArgumentException iae) {
localLevel = LogLevel.DEBUG;
}
this.level = localLevel;
String msg = event.getFormattedMessage();
IThrowableProxy tp = event.getThrowableProxy();
if (tp == null) {
exception = "";
} else {
StringBuilder buf = new StringBuilder(32);
for (IThrowableProxy currentThrowable = tp; currentThrowable != null; currentThrowable = currentThrowable.getCause()) {
LogEntryImpl.subjoinThrowableProxy(buf, currentThrowable);
}
exception = buf.toString();
}
if (maxSize > 0 && msg.length() + exception.length() > maxSize) {
if (msg.length() > maxSize / 2) {
msg = msg.substring(0, maxSize / 2).concat("...");
}
if (exception.length() > maxSize / 2) {
exception = exception.substring(0, maxSize / 2).concat("...");
}
}
this.message = msg;
this.exceptionOutput = exception;
this.name = event.getLoggerName();
this.timestamp = event.getTimeStamp();
this.threadName = event.getThreadName();
}
@Override
public LogLevel getLogLevel() {
return this.level;
}
@Override
public String getMessage() {
return this.message;
}
@Override
public String getLoggerName() {
return this.name;
}
@Override
public long getTimeStamp() {
return this.timestamp;
}
@Override
public String getThreadName() {
return this.threadName;
}
@Override
public String getExceptionOutput() {
return this.exceptionOutput;
}
private static void subjoinThrowableProxy(StringBuilder buf, IThrowableProxy tp) {
ThrowableProxyUtil.subjoinFirstLine((StringBuilder)buf, (IThrowableProxy)tp);
buf.append(LINE_SEPARATOR);
StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
int commonFrames = tp.getCommonFrames();
int maxIndex = stepArray.length;
if (commonFrames > 0) {
maxIndex -= commonFrames;
}
for (int i = 0; i < maxIndex; ++i) {
String string = stepArray[i].toString();
buf.append('\t');
buf.append(string);
LogEntryImpl.extraData(buf, stepArray[i]);
buf.append(LINE_SEPARATOR);
}
if (commonFrames > 0) {
buf.append("\t... ").append(tp.getCommonFrames()).append(" common frames omitted").append(LINE_SEPARATOR);
}
}
private static void extraData(StringBuilder builder, StackTraceElementProxy step) {
if (step != null) {
ThrowableProxyUtil.subjoinPackagingData((StringBuilder)builder, (StackTraceElementProxy)step);
}
}
}