4646import sun .security .x509 .*;
4747
4848import static java .nio .charset .StandardCharsets .UTF_8 ;
49+ import static sun .security .ssl .Utilities .LINE_SEP ;
4950
5051/**
5152 * Implementation of SSL logger.
@@ -62,6 +63,7 @@ public final class SSLLogger {
6263 private static final String property ;
6364 public static final boolean isOn ;
6465
66+
6567 static {
6668 String p = System .getProperty ("javax.net.debug" );
6769 if (p != null ) {
@@ -190,7 +192,12 @@ private static void log(Level level, String msg, Object... params) {
190192 try {
191193 String formatted =
192194 SSLSimpleFormatter .formatParameters (params );
193- logger .log (level , msg , formatted );
195+ // use the customized log method for SSLConsoleLogger
196+ if (logger instanceof SSLConsoleLogger ) {
197+ logger .log (level , msg , formatted );
198+ } else {
199+ logger .log (level , msg + ":" + LINE_SEP + formatted );
200+ }
194201 } catch (Exception exp ) {
195202 // ignore it, just for debugging.
196203 }
@@ -282,7 +289,7 @@ private static class SSLSimpleFormatter {
282289 """ ,
283290 Locale .ENGLISH );
284291
285- private static final MessageFormat extendedCertFormart =
292+ private static final MessageFormat extendedCertFormat =
286293 new MessageFormat (
287294 """
288295 "version" : "v{0}",
@@ -299,15 +306,6 @@ private static class SSLSimpleFormatter {
299306 """ ,
300307 Locale .ENGLISH );
301308
302- //
303- // private static MessageFormat certExtFormat = new MessageFormat(
304- // "{0} [{1}] '{'\n" +
305- // " critical: {2}\n" +
306- // " value: {3}\n" +
307- // "'}'",
308- // Locale.ENGLISH);
309- //
310-
311309 private static final MessageFormat messageFormatNoParas =
312310 new MessageFormat (
313311 """
@@ -325,7 +323,7 @@ private static class SSLSimpleFormatter {
325323
326324 private static final MessageFormat messageCompactFormatNoParas =
327325 new MessageFormat (
328- "{0}|{1}|{2}|{3}|{4}|{5}|{6}\n " ,
326+ "{0}|{1}|{2}|{3}|{4}|{5}|{6}" + LINE_SEP ,
329327 Locale .ENGLISH );
330328
331329 private static final MessageFormat messageFormatWithParas =
@@ -423,7 +421,7 @@ private static String formatParameters(Object ... parameters) {
423421 if (isFirst ) {
424422 isFirst = false ;
425423 } else {
426- builder .append (",\n " );
424+ builder .append ("," + LINE_SEP );
427425 }
428426
429427 if (parameter instanceof Throwable ) {
@@ -504,10 +502,10 @@ private static String formatCertificate(Certificate certificate) {
504502 if (isFirst ) {
505503 isFirst = false ;
506504 } else {
507- extBuilder .append (",\n " );
505+ extBuilder .append ("," + LINE_SEP );
508506 }
509- extBuilder .append ("{\n " +
510- Utilities .indent (certExt .toString ()) + " \n }" );
507+ extBuilder .append ("{" + LINE_SEP +
508+ Utilities .indent (certExt .toString ()) + LINE_SEP + " }" );
511509 }
512510 Object [] certFields = {
513511 x509 .getVersion (),
@@ -521,7 +519,7 @@ private static String formatCertificate(Certificate certificate) {
521519 Utilities .indent (extBuilder .toString ())
522520 };
523521 builder .append (Utilities .indent (
524- extendedCertFormart .format (certFields )));
522+ extendedCertFormat .format (certFields )));
525523 }
526524 } catch (Exception ce ) {
527525 // ignore the exception
@@ -578,15 +576,15 @@ private static String formatMapEntry(Map.Entry<String, ?> entry) {
578576 // "string c"
579577 // ]
580578 StringBuilder builder = new StringBuilder (512 );
581- builder .append ("\" " + key + "\" : [\n " );
579+ builder .append ("\" " + key + "\" : [" + LINE_SEP );
582580 int len = strings .length ;
583581 for (int i = 0 ; i < len ; i ++) {
584582 String string = strings [i ];
585583 builder .append (" \" " + string + "\" " );
586584 if (i != len - 1 ) {
587585 builder .append ("," );
588586 }
589- builder .append (" \n " );
587+ builder .append (LINE_SEP );
590588 }
591589 builder .append (" ]" );
592590
0 commit comments