4141public class Debug {
4242
4343 private String prefix ;
44- private boolean printDateTime ;
45- private boolean printThreadDetails ;
46-
4744 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" ;
5245
5346 static {
5447 args = System .getProperty ("java.security.debug" );
@@ -66,16 +59,6 @@ public class Debug {
6659 args = args .toLowerCase (Locale .ENGLISH );
6760 if (args .equals ("help" )) {
6861 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 );
7962 }
8063 }
8164 }
@@ -106,11 +89,6 @@ public static void Help() {
10689 System .err .println ("ts timestamping" );
10790 System .err .println ("x509 X.509 certificate debugging" );
10891 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 ();
11492 System .err .println ("The following can be used with provider:" );
11593 System .err .println ();
11694 System .err .println ("engine=<engines>" );
@@ -151,7 +129,6 @@ public static Debug getInstance(String option, String prefix) {
151129 if (isOn (option )) {
152130 Debug d = new Debug ();
153131 d .prefix = prefix ;
154- d .configureExtras (option );
155132 return d ;
156133 } else {
157134 return null ;
@@ -166,32 +143,6 @@ private static String formatCaller() {
166143 .findFirst ().orElse ("unknown caller" ));
167144 }
168145
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- }
195146
196147 /**
197148 * Get a Debug object corresponding to the given option on the given
@@ -208,11 +159,6 @@ private void configureExtras(String option) {
208159 * Debug debug = Debug.of("login", property);
209160 * }
210161 *
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- *
216162 * @param prefix the debug option name
217163 * @param property debug setting for this option
218164 * @return a new Debug object if the property is true
@@ -221,8 +167,6 @@ public static Debug of(String prefix, String property) {
221167 if (property != null && property .toLowerCase (Locale .ROOT ).startsWith ("true" )) {
222168 Debug d = new Debug ();
223169 d .prefix = prefix ;
224- d .printThreadDetails = property .contains (THREAD_OPTION );
225- d .printDateTime = property .contains (TIMESTAMP_OPTION );
226170 return d ;
227171 }
228172 return null ;
@@ -285,23 +229,18 @@ public void println(String prefix, String message) {
285229 }
286230
287231 /**
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
292237 */
293238 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 ()));
305244 }
306245
307246 /**
0 commit comments