jdk/src/java.base/share/classes/sun/util/logging/LoggingSupport.java
author dfuchs
Wed, 25 Feb 2015 18:41:07 +0100
changeset 29117 7956b5dc0eac
parent 25859 3317bb8137f4
permissions -rw-r--r--
8072645: java.util.logging should use java.time to get more precise time stamps Summary: j.u.logging uses j.t.Instant to store LogRecord time stamps. XMLFormatter format is updated to allow for a new optional <nanos> element containing a nano second adjustment. SimpleFormatter passes a ZonedDateTime object to String.format. LogRecord getMillis/setMillis are deprecated, replaced by getInstant/setInstant. Reviewed-by: scolebourne, plevart, rriggs Contributed-by: daniel.fuchs@oracle.com, peter.levart@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
     1
/*
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
     4
 *
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    10
 *
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    15
 * accompanied this code).
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    16
 *
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4172
diff changeset
    23
 * questions.
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    24
 */
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    25
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    26
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    27
package sun.util.logging;
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    28
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    29
import java.lang.reflect.Field;
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    30
import java.security.AccessController;
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    31
import java.security.PrivilegedAction;
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
    32
import java.time.ZonedDateTime;
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    33
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    34
/**
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    35
 * Internal API to support JRE implementation to detect if the java.util.logging
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    36
 * support is available but with no dependency on the java.util.logging
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    37
 * classes.  This LoggingSupport class provides several static methods to
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    38
 * access the java.util.logging functionality that requires the caller
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    39
 * to ensure that the logging support is {@linkplain #isAvailable available}
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    40
 * before invoking it.
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    41
 *
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    42
 * @see sun.util.logging.PlatformLogger if you want to log messages even
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    43
 * if the logging support is not available
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    44
 */
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    45
public class LoggingSupport {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    46
    private LoggingSupport() { }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    47
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    48
    private static final LoggingProxy proxy =
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    49
        AccessController.doPrivileged(new PrivilegedAction<LoggingProxy>() {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    50
            public LoggingProxy run() {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    51
                try {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    52
                    // create a LoggingProxyImpl instance when
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    53
                    // java.util.logging classes exist
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    54
                    Class<?> c = Class.forName("java.util.logging.LoggingProxyImpl", true, null);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    55
                    Field f = c.getDeclaredField("INSTANCE");
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    56
                    f.setAccessible(true);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    57
                    return (LoggingProxy) f.get(null);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    58
                } catch (ClassNotFoundException cnf) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    59
                    return null;
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    60
                } catch (NoSuchFieldException e) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    61
                    throw new AssertionError(e);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    62
                } catch (IllegalAccessException e) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    63
                    throw new AssertionError(e);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    64
                }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    65
            }});
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    66
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    67
    /**
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    68
     * Returns true if java.util.logging support is available.
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    69
     */
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    70
    public static boolean isAvailable() {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    71
        return proxy != null;
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    72
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    73
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    74
    private static void ensureAvailable() {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    75
        if (proxy == null)
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    76
            throw new AssertionError("Should not here");
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    77
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    78
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    79
    public static java.util.List<String> getLoggerNames() {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    80
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    81
        return proxy.getLoggerNames();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    82
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    83
    public static String getLoggerLevel(String loggerName) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    84
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    85
        return proxy.getLoggerLevel(loggerName);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    86
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    87
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    88
    public static void setLoggerLevel(String loggerName, String levelName) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    89
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    90
        proxy.setLoggerLevel(loggerName, levelName);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    91
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    92
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    93
    public static String getParentLoggerName(String loggerName) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    94
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    95
        return proxy.getParentLoggerName(loggerName);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    96
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    97
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    98
    public static Object getLogger(String name) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
    99
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   100
        return proxy.getLogger(name);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   101
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   102
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   103
    public static Object getLevel(Object logger) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   104
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   105
        return proxy.getLevel(logger);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   106
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   107
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   108
    public static void setLevel(Object logger, Object newLevel) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   109
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   110
        proxy.setLevel(logger, newLevel);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   111
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   112
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   113
    public static boolean isLoggable(Object logger, Object level) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   114
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   115
        return proxy.isLoggable(logger,level);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   116
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   117
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   118
    public static void log(Object logger, Object level, String msg) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   119
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   120
        proxy.log(logger, level, msg);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   121
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   122
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   123
    public static void log(Object logger, Object level, String msg, Throwable t) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   124
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   125
        proxy.log(logger, level, msg, t);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   126
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   127
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   128
    public static void log(Object logger, Object level, String msg, Object... params) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   129
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   130
        proxy.log(logger, level, msg, params);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   131
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   132
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   133
    public static Object parseLevel(String levelName) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   134
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   135
        return proxy.parseLevel(levelName);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   136
    }
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   137
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   138
    public static String getLevelName(Object level) {
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   139
        ensureAvailable();
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   140
        return proxy.getLevelName(level);
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   141
    }
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   142
16736
f1e17f49191a 8011380: FX dependency on PlatformLogger broken by 8010309
mchung
parents: 14342
diff changeset
   143
    public static int getLevelValue(Object level) {
f1e17f49191a 8011380: FX dependency on PlatformLogger broken by 8010309
mchung
parents: 14342
diff changeset
   144
        ensureAvailable();
f1e17f49191a 8011380: FX dependency on PlatformLogger broken by 8010309
mchung
parents: 14342
diff changeset
   145
        return proxy.getLevelValue(level);
f1e17f49191a 8011380: FX dependency on PlatformLogger broken by 8010309
mchung
parents: 14342
diff changeset
   146
    }
f1e17f49191a 8011380: FX dependency on PlatformLogger broken by 8010309
mchung
parents: 14342
diff changeset
   147
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   148
    // Since JDK 9, logging uses java.time to get more precise time stamps.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   149
    // It is possible to configure the simple format to print nano seconds (.%1$tN)
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   150
    // by specifying:
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   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
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   152
    // in the logging configuration
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   153
    private static final String DEFAULT_FORMAT =
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   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";
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   155
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   156
    private static final String FORMAT_PROP_KEY = "java.util.logging.SimpleFormatter.format";
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   157
    public static String getSimpleFormat() {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   158
        return getSimpleFormat(true);
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   159
    }
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   160
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   161
    // useProxy if true will cause initialization of
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   162
    // java.util.logging and read its configuration
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   163
    static String getSimpleFormat(boolean useProxy) {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   164
        String format =
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   165
            AccessController.doPrivileged(
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   166
                new PrivilegedAction<String>() {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   167
                    public String run() {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   168
                        return System.getProperty(FORMAT_PROP_KEY);
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   169
                    }
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   170
                });
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   171
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   172
        if (useProxy && proxy != null && format == null) {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   173
            format = proxy.getProperty(FORMAT_PROP_KEY);
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   174
        }
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   175
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   176
        if (format != null) {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   177
            try {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   178
                // validate the user-defined format string
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   179
                String.format(format, ZonedDateTime.now(), "", "", "", "", "");
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   180
            } catch (IllegalArgumentException e) {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   181
                // illegal syntax; fall back to the default format
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   182
                format = DEFAULT_FORMAT;
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   183
            }
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   184
        } else {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   185
            format = DEFAULT_FORMAT;
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   186
        }
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   187
        return format;
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   188
    }
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   189
4172
bceea7bc12b7 6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
diff changeset
   190
}