FormsLogger.java
10.2 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.logging.AdobeLogger
* com.adobe.logging.Msg0
* com.adobe.logging.Msg1
* com.adobe.logging.Msg2
* com.adobe.logging.Msg3
* com.adobe.service.logging.Level
*/
package com.adobe.livecycle.formsservice.logging;
import com.adobe.livecycle.formsservice.client.RenderOptionsSpec;
import com.adobe.logging.AdobeLogger;
import com.adobe.logging.Msg0;
import com.adobe.logging.Msg1;
import com.adobe.logging.Msg2;
import com.adobe.logging.Msg3;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Level;
public class FormsLogger {
public static final int LOG_FATAL = 0;
public static final int LOG_ALERT = 1;
public static final int LOG_CRITICAL = 2;
public static final int LOG_ERROR = 3;
public static final int LOG_WARN = 4;
public static final int LOG_NOTICE = 5;
public static final int LOG_INFO = 6;
public static final int LOG_DEBUG = 7;
public static final int LOG_PERFORMANCE = 5;
public static final String NEWLINE = System.getProperty("java.line.separator");
public static final String FRM_PERF_KW = "ALC-FRM-PRF:";
public static final String OUT_PERF_KW = "ALC-OUT-PRF:";
public static final String PERF_KW = " !PERFORMANCE! ";
public static final String DEF_FS_LOGGING_BUNDLE = "com.adobe.livecycle.formsservice.logging.FRM";
public static final String SERVICE_FORMS = "FormsService";
public static final String SERVICE_OUTPUT = "OutputService";
public static Boolean bIsDebugLevel = null;
private static final String FORM_KEY = "Form Query or UUID : [";
private static final String CONTENT_ROOT_URI = "Content Root Uri : [";
private static final String NO_FORMS_KEY_SET = "No Form Key Set";
private static final char CLOSE_PAREN = ']';
private static ThreadLocal<String> serviceName = new ThreadLocal();
private static ThreadLocal<Boolean> bPerfLoggingEnabled = new ThreadLocal();
private static ThreadLocal<ArrayList<String>> oTLBuffer = new ThreadLocal();
private static ThreadLocal<String> formsKeys = new ThreadLocal();
public static String getResourceString(ResourceBundle bundle, String resourceID) {
return FormsLogger.getResourceString(bundle, resourceID, Locale.getDefault());
}
public static String getResourceString(ResourceBundle bundle, String resourceID, Locale locale) {
if (bundle == null) {
bundle = ResourceBundle.getBundle("com.adobe.livecycle.formsservice.logging.FRM", locale);
}
return (String)bundle.getObject(resourceID);
}
public static String getResourceString(String resourceID) {
return FormsLogger.getResourceString(null, resourceID);
}
public static String getResourceString(String resourceID, Locale locale) {
return FormsLogger.getResourceString(null, resourceID, locale);
}
public static String getResourceString(ResourceBundle bundle, String resourceID, String[] args) {
return FormsLogger.getResourceString(bundle, resourceID, Locale.getDefault(), args);
}
public static String getResourceString(ResourceBundle bundle, String resourceID, Locale locale, String[] args) {
if (bundle == null) {
bundle = ResourceBundle.getBundle("com.adobe.livecycle.formsservice.logging.FRM");
}
String res = (String)bundle.getObject(resourceID);
if (args != null) {
for (int i = 0; i < args.length; ++i) {
String tok = "{" + i + "}";
int j = res.indexOf(tok);
if (j < 0) continue;
res = res.substring(0, j) + args[i] + res.substring(j + tok.length());
}
}
return res;
}
public static String getResourceString(String resourceID, String[] args) {
return FormsLogger.getResourceString(null, resourceID, args);
}
public static String getResourceString(String resourceID, Locale locale, String[] args) {
return FormsLogger.getResourceString(null, resourceID, locale, args);
}
public static void logMessage(Class oClass, int severity, ResourceBundle bundle, String resourceID) {
FormsLogger.logMessage(oClass, severity, bundle, resourceID, null);
}
public static void logMessage(Class oClass, int severity, String resourceID) {
FormsLogger.logMessage(oClass, severity, null, resourceID);
}
public static void logMessage(Class oClass, int severity, String resourceID, String[] args) {
FormsLogger.logMessage(oClass, severity, null, resourceID, args);
}
public static void logMessage(Class oClass, int severity, ResourceBundle bundle, String resourceID, String[] args) {
try {
String sLogString = FormsLogger.getResourceString(bundle, resourceID);
if (sLogString == null || sLogString.length() == 0) {
sLogString = "** this msg not found in resources **";
}
AdobeLogger logger = AdobeLogger.getAdobeLogger((Class)oClass);
com.adobe.service.logging.Level adobeLevel = com.adobe.service.logging.Level.toLevel((int)severity);
if (serviceName.get() != null && serviceName.get().equalsIgnoreCase("OutputService")) {
resourceID = resourceID.substring(0, 3) + "-OUT-002-" + resourceID.substring(12, 15);
}
if (args == null) {
logger.log(new Msg0(resourceID, adobeLevel.jdkLevel(), sLogString));
} else if (args.length == 1) {
logger.log(new Msg1(resourceID, adobeLevel.jdkLevel(), sLogString), (Object)args[0]);
} else if (args.length == 2) {
logger.log(new Msg2(resourceID, adobeLevel.jdkLevel(), sLogString), (Object)args[0], (Object)args[1]);
} else if (args.length >= 3) {
logger.log(new Msg3(resourceID, adobeLevel.jdkLevel(), sLogString), (Object)args[0], (Object)args[1], (Object)args[2]);
}
}
catch (Exception e) {
String err = e.getMessage();
if (err == null) {
err = e.getClass().getName();
}
System.out.print("[FormServer] logMessage error: " + e + " args passed: ");
for (int i = 0; i < args.length; ++i) {
System.out.print(args[i]);
}
System.out.println("");
}
}
public static void logInfo(Class oClass, String text) {
FormsLogger.logMessage(oClass, 6, "ALC-FRM-001-501", new String[]{text});
}
public static void logDebug(Class oClass, String text) {
FormsLogger.logMessage(oClass, 7, "ALC-FRM-001-501", new String[]{text});
}
public static long logPerformance(boolean diff, long timeStamp, String text) {
if (!FormsLogger.getPerformanceLogEnabled()) {
return -1;
}
if (!diff) {
FormsLogger.logPMessage(new String[]{text});
return System.nanoTime();
}
long difference = System.nanoTime() - timeStamp;
FormsLogger.logPMessage(new String[]{text, "" + difference});
return 0;
}
private static void logPMessage(String[] args) {
ArrayList<String> oThreadLocalBuffer = FormsLogger.getBuffer();
if (oThreadLocalBuffer != null) {
StringBuffer oMsg = new StringBuffer();
if (serviceName.get() != null && serviceName.get().equalsIgnoreCase("OutputService")) {
oMsg.append("ALC-OUT-PRF:");
} else {
oMsg.append("ALC-FRM-PRF:");
}
oMsg.append(" !PERFORMANCE! ");
if (args.length == 1) {
oMsg.append(args[0]);
} else if (args.length == 2) {
oMsg.append(args[0]).append(" :").append(args[1]).append("ns");
}
oThreadLocalBuffer.add(oMsg.toString());
}
}
public static void logFormRenderRequestInfo(Class oClass, String sFormQuery, String sFormPreference, RenderOptionsSpec cOptionsBean, String sUserAgent, String sApplicationWebRoot, String sTargetURL, String sContentRootURI, String sBaseURL) {
StringBuffer logBuffer = new StringBuffer();
logBuffer.append("FormName: ").append(sFormQuery).append(", FormPreference: ").append(sFormPreference).append(", Debug: ").append(cOptionsBean.isDebugEnabled()).append(", PDFVersion: ").append(cOptionsBean.getPDFVersion()).append(", Content Root: ").append(sContentRootURI).append(", Base URL: ").append(sBaseURL).append(", App Root: ").append(sApplicationWebRoot).append(", User Agent: ").append(sUserAgent);
FormsLogger.logMessage(oClass, 7, "ALC-FRM-001-501", new String[]{logBuffer.toString()});
}
public static ArrayList<String> getBuffer() {
return oTLBuffer.get();
}
public static void setBuffer(ArrayList<String> oList) {
oTLBuffer.set(oList);
}
public static boolean getPerformanceLogEnabled() {
return bPerfLoggingEnabled.get() != null && bPerfLoggingEnabled.get() != false;
}
public static void setPerformanceLogEnabled(boolean bEnable) {
bPerfLoggingEnabled.set(bEnable);
}
public static void setServiceName(String name) {
serviceName.set(name);
}
public static void setFormKey(String key, String contentRootUri) {
if (FormsLogger.getPerformanceLogEnabled()) {
StringBuffer strBuffer = new StringBuffer(100);
if (key != null && key.length() > 0) {
strBuffer.append("Form Query or UUID : [" + key).append(']');
} else {
strBuffer.append("No Form Key Set");
}
if (contentRootUri != null && contentRootUri.length() > 0) {
strBuffer.append(',').append("Content Root Uri : [").append(contentRootUri).append(']');
}
formsKeys.set(strBuffer.toString());
}
}
public static String getFormKey() {
return formsKeys.get();
}
public static boolean isDebugLevel(Class oClass) {
AdobeLogger oLogger = AdobeLogger.getAdobeLogger((Class)oClass);
if (oLogger == null) {
return false;
}
return oLogger.isLoggable(com.adobe.service.logging.Level.DEBUG.jdkLevel());
}
}