jdk/src/java.base/share/classes/sun/util/logging/LoggingSupport.java
changeset 29117 7956b5dc0eac
parent 25859 3317bb8137f4
equal deleted inserted replaced
29116:9918719cfcc0 29117:7956b5dc0eac
     1 /*
     1 /*
     2  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    27 package sun.util.logging;
    27 package sun.util.logging;
    28 
    28 
    29 import java.lang.reflect.Field;
    29 import java.lang.reflect.Field;
    30 import java.security.AccessController;
    30 import java.security.AccessController;
    31 import java.security.PrivilegedAction;
    31 import java.security.PrivilegedAction;
    32 import java.util.Date;
    32 import java.time.ZonedDateTime;
    33 
    33 
    34 /**
    34 /**
    35  * Internal API to support JRE implementation to detect if the java.util.logging
    35  * Internal API to support JRE implementation to detect if the java.util.logging
    36  * support is available but with no dependency on the java.util.logging
    36  * support is available but with no dependency on the java.util.logging
    37  * classes.  This LoggingSupport class provides several static methods to
    37  * classes.  This LoggingSupport class provides several static methods to
   143     public static int getLevelValue(Object level) {
   143     public static int getLevelValue(Object level) {
   144         ensureAvailable();
   144         ensureAvailable();
   145         return proxy.getLevelValue(level);
   145         return proxy.getLevelValue(level);
   146     }
   146     }
   147 
   147 
       
   148     // Since JDK 9, logging uses java.time to get more precise time stamps.
       
   149     // It is possible to configure the simple format to print nano seconds (.%1$tN)
       
   150     // by specifying:
       
   151     // java.util.logging.SimpleFormatter.format=%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS.%1$tN %1$Tp %2$s%n%4$s: %5$s%6$s%n
       
   152     // in the logging configuration
   148     private static final String DEFAULT_FORMAT =
   153     private static final String DEFAULT_FORMAT =
   149         "%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%6$s%n";
   154         "%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%6$s%n";
   150 
   155 
   151     private static final String FORMAT_PROP_KEY = "java.util.logging.SimpleFormatter.format";
   156     private static final String FORMAT_PROP_KEY = "java.util.logging.SimpleFormatter.format";
   152     public static String getSimpleFormat() {
   157     public static String getSimpleFormat() {
   169         }
   174         }
   170 
   175 
   171         if (format != null) {
   176         if (format != null) {
   172             try {
   177             try {
   173                 // validate the user-defined format string
   178                 // validate the user-defined format string
   174                 String.format(format, new Date(), "", "", "", "", "");
   179                 String.format(format, ZonedDateTime.now(), "", "", "", "", "");
   175             } catch (IllegalArgumentException e) {
   180             } catch (IllegalArgumentException e) {
   176                 // illegal syntax; fall back to the default format
   181                 // illegal syntax; fall back to the default format
   177                 format = DEFAULT_FORMAT;
   182                 format = DEFAULT_FORMAT;
   178             }
   183             }
   179         } else {
   184         } else {