41
41
public class Debug {
42
42
43
43
private String prefix ;
44
- private boolean printDateTime ;
45
- private boolean printThreadDetails ;
46
-
47
44
private static String args ;
48
- private static boolean threadInfoAll ;
49
- private static boolean timeStampInfoAll ;
50
- private static final String TIMESTAMP_OPTION = "+timestamp" ;
51
- private static final String THREAD_OPTION = "+thread" ;
52
45
53
46
static {
54
47
args = System .getProperty ("java.security.debug" );
@@ -66,16 +59,6 @@ public class Debug {
66
59
args = args .toLowerCase (Locale .ENGLISH );
67
60
if (args .equals ("help" )) {
68
61
Help ();
69
- } else if (args .contains ("all" )) {
70
- // "all" option has special handling for decorator options
71
- // If the thread or timestamp decorator option is detected
72
- // with the "all" option, then it impacts decorator options
73
- // for other categories
74
- int beginIndex = args .lastIndexOf ("all" ) + "all" .length ();
75
- int commaIndex = args .indexOf (',' , beginIndex );
76
- if (commaIndex == -1 ) commaIndex = args .length ();
77
- threadInfoAll = args .substring (beginIndex , commaIndex ).contains (THREAD_OPTION );
78
- timeStampInfoAll = args .substring (beginIndex , commaIndex ).contains (TIMESTAMP_OPTION );
79
62
}
80
63
}
81
64
}
@@ -106,11 +89,6 @@ public static void Help() {
106
89
System .err .println ("ts timestamping" );
107
90
System .err .println ("x509 X.509 certificate debugging" );
108
91
System .err .println ();
109
- System .err .println ("+timestamp can be appended to any of above options to print" );
110
- System .err .println (" a timestamp for that debug option" );
111
- System .err .println ("+thread can be appended to any of above options to print" );
112
- System .err .println (" thread and caller information for that debug option" );
113
- System .err .println ();
114
92
System .err .println ("The following can be used with provider:" );
115
93
System .err .println ();
116
94
System .err .println ("engine=<engines>" );
@@ -151,7 +129,6 @@ public static Debug getInstance(String option, String prefix) {
151
129
if (isOn (option )) {
152
130
Debug d = new Debug ();
153
131
d .prefix = prefix ;
154
- d .configureExtras (option );
155
132
return d ;
156
133
} else {
157
134
return null ;
@@ -166,32 +143,6 @@ private static String formatCaller() {
166
143
.findFirst ().orElse ("unknown caller" ));
167
144
}
168
145
169
- // parse an option string to determine if extra details,
170
- // like thread and timestamp, should be printed
171
- private void configureExtras (String option ) {
172
- // treat "all" as special case, only used for java.security.debug property
173
- this .printDateTime = timeStampInfoAll ;
174
- this .printThreadDetails = threadInfoAll ;
175
-
176
- if (printDateTime && printThreadDetails ) {
177
- // nothing left to configure
178
- return ;
179
- }
180
-
181
- // args is converted to lower case for the most part via marshal method
182
- int optionIndex = args .lastIndexOf (option );
183
- if (optionIndex == -1 ) {
184
- // option not in args list. Only here since "all" was present
185
- // in debug property argument. "all" option already parsed
186
- return ;
187
- }
188
- int beginIndex = optionIndex + option .length ();
189
- int commaIndex = args .indexOf (',' , beginIndex );
190
- if (commaIndex == -1 ) commaIndex = args .length ();
191
- String subOpt = args .substring (beginIndex , commaIndex );
192
- printDateTime = printDateTime || subOpt .contains (TIMESTAMP_OPTION );
193
- printThreadDetails = printThreadDetails || subOpt .contains (THREAD_OPTION );
194
- }
195
146
196
147
/**
197
148
* Get a Debug object corresponding to the given option on the given
@@ -208,11 +159,6 @@ private void configureExtras(String option) {
208
159
* Debug debug = Debug.of("login", property);
209
160
* }
210
161
*
211
- * +timestamp string can be appended to property value
212
- * to print timestamp information. (e.g. true+timestamp)
213
- * +thread string can be appended to property value
214
- * to print thread and caller information. (e.g. true+thread)
215
- *
216
162
* @param prefix the debug option name
217
163
* @param property debug setting for this option
218
164
* @return a new Debug object if the property is true
@@ -221,8 +167,6 @@ public static Debug of(String prefix, String property) {
221
167
if (property != null && property .toLowerCase (Locale .ROOT ).startsWith ("true" )) {
222
168
Debug d = new Debug ();
223
169
d .prefix = prefix ;
224
- d .printThreadDetails = property .contains (THREAD_OPTION );
225
- d .printDateTime = property .contains (TIMESTAMP_OPTION );
226
170
return d ;
227
171
}
228
172
return null ;
@@ -285,23 +229,18 @@ public void println(String prefix, String message) {
285
229
}
286
230
287
231
/**
288
- * If thread debug option enabled, include information containing
289
- * hex value of threadId and the current thread name
290
- * If timestamp debug option enabled, include timestamp string
291
- * @return extra info if debug option enabled.
232
+ * Include information containing:
233
+ * - hex value of threadId
234
+ * - the current thread name
235
+ * - timestamp string
236
+ * @return String with above metadata
292
237
*/
293
238
private String extraInfo () {
294
- String retString = "" ;
295
- if (printThreadDetails ) {
296
- retString = "0x" + Long .toHexString (
297
- Thread .currentThread ().threadId ()).toUpperCase (Locale .ROOT ) +
298
- "|" + Thread .currentThread ().getName () + "|" + formatCaller ();
299
- }
300
- if (printDateTime ) {
301
- retString += (retString .isEmpty () ? "" : "|" )
302
- + FormatHolder .DATE_TIME_FORMATTER .format (Instant .now ());
303
- }
304
- return retString .isEmpty () ? "" : "[" + retString + "]" ;
239
+ return String .format ("[0x%s|%s|%s|%s]" ,
240
+ Long .toHexString (Thread .currentThread ().threadId ()).toUpperCase (Locale .ROOT ),
241
+ Thread .currentThread ().getName (),
242
+ formatCaller (),
243
+ FormatHolder .DATE_TIME_FORMATTER .format (Instant .now ()));
305
244
}
306
245
307
246
/**
0 commit comments