jdk/test/java/lang/System/LoggerFinder/internal/PlatformLoggerBridgeTest/PlatformLoggerBridgeTest.java
author dfuchs
Wed, 27 Apr 2016 18:04:16 +0200
changeset 37672 03684934dc09
parent 36237 963d1115678b
child 44545 83b611b88ac8
permissions -rw-r--r--
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class. Summary: Changes System.LoggerFinder methods to take a Module argument instead of a Class. Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     1
/*
36237
963d1115678b 8150998: Fix module dependences in java/lang tests
shurailine
parents: 33875
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     4
 *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     8
 *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    14
 *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    18
 *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    21
 * questions.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    22
 */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    23
import java.security.AccessControlException;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    24
import java.security.AccessController;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    25
import java.security.CodeSource;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    26
import java.security.Permission;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    27
import java.security.PermissionCollection;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    28
import java.security.Permissions;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    29
import java.security.Policy;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    30
import java.security.PrivilegedAction;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    31
import java.security.ProtectionDomain;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    32
import java.util.Arrays;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    33
import java.util.Collections;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    34
import java.util.Enumeration;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    35
import java.util.HashMap;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    36
import java.util.Map;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    37
import java.util.Objects;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    38
import java.util.Queue;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    39
import java.util.ResourceBundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    40
import java.util.concurrent.ArrayBlockingQueue;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    41
import java.util.concurrent.ConcurrentHashMap;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    42
import java.util.concurrent.atomic.AtomicBoolean;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    43
import java.util.concurrent.atomic.AtomicLong;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    44
import java.util.function.Supplier;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    45
import java.util.logging.Handler;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    46
import java.util.logging.LogRecord;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    47
import java.lang.System.LoggerFinder;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    48
import java.lang.System.Logger;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    49
import java.lang.System.Logger.Level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    50
import java.util.stream.Stream;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    51
import sun.util.logging.PlatformLogger;
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 36237
diff changeset
    52
import java.lang.reflect.Module;
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    53
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    54
/**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    55
 * @test
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    56
 * @bug     8140364
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    57
 * @summary JDK implementation specific unit test for JDK internal artifacts.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    58
 *          Tests all bridge methods from PlatformLogger with the a custom
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    59
 *          backend whose loggers implement PlatformLogger.Bridge.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    60
 * @modules java.base/sun.util.logging
36237
963d1115678b 8150998: Fix module dependences in java/lang tests
shurailine
parents: 33875
diff changeset
    61
 *          java.logging
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    62
 * @build CustomSystemClassLoader PlatformLoggerBridgeTest
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    63
 * @run  main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest NOSECURITY
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    64
 * @run  main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest NOPERMISSIONS
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    65
 * @run  main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest WITHPERMISSIONS
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    66
 * @author danielfuchs
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    67
 */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    68
public class PlatformLoggerBridgeTest {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    69
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    70
    static final RuntimePermission LOGGERFINDER_PERMISSION =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    71
                new RuntimePermission("loggerFinder");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    72
    final static AtomicLong sequencer = new AtomicLong();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    73
    final static boolean VERBOSE = false;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    74
    static final ThreadLocal<AtomicBoolean> allowControl = new ThreadLocal<AtomicBoolean>() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    75
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    76
        protected AtomicBoolean initialValue() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    77
            return  new AtomicBoolean(false);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    78
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    79
    };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    80
    static final ThreadLocal<AtomicBoolean> allowAccess = new ThreadLocal<AtomicBoolean>() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    81
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    82
        protected AtomicBoolean initialValue() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    83
            return  new AtomicBoolean(false);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    84
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    85
    };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    86
    static final ThreadLocal<AtomicBoolean> allowAll = new ThreadLocal<AtomicBoolean>() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    87
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    88
        protected AtomicBoolean initialValue() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    89
            return  new AtomicBoolean(false);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    90
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    91
    };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    92
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    93
    static final Class<?> providerClass;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    94
    static {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    95
        try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    96
            // Preload classes before the security manager is on.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    97
            providerClass = ClassLoader.getSystemClassLoader().loadClass("PlatformLoggerBridgeTest$LogProducerFinder");
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 36237
diff changeset
    98
            ((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass.getModule());
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    99
        } catch (Exception ex) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   100
            throw new ExceptionInInitializerError(ex);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   101
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   102
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   103
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   104
    public static final Queue<LogEvent> eventQueue = new ArrayBlockingQueue<>(128);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   105
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   106
    public static final class LogEvent implements Cloneable {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   107
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   108
        public LogEvent() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   109
            this(sequencer.getAndIncrement());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   110
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   111
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   112
        LogEvent(long sequenceNumber) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   113
            this.sequenceNumber = sequenceNumber;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   114
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   115
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   116
        long sequenceNumber;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   117
        boolean isLoggable;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   118
        String loggerName;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   119
        sun.util.logging.PlatformLogger.Level level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   120
        ResourceBundle bundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   121
        Throwable thrown;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   122
        Object[] args;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   123
        String msg;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   124
        Supplier<String> supplier;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   125
        String className;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   126
        String methodName;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   127
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   128
        Object[] toArray() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   129
            return new Object[] {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   130
                sequenceNumber,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   131
                loggerName,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   132
                level,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   133
                isLoggable,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   134
                bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   135
                msg,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   136
                supplier,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   137
                thrown,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   138
                args,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   139
                className,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   140
                methodName,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   141
            };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   142
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   143
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   144
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   145
        public String toString() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   146
            return Arrays.deepToString(toArray());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   147
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   148
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   149
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   150
        public boolean equals(Object obj) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   151
            return obj instanceof LogEvent
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   152
                    && Objects.deepEquals(this.toArray(), ((LogEvent)obj).toArray());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   153
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   154
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   155
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   156
        public int hashCode() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   157
            return Objects.hash(toArray());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   158
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   159
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   160
        public LogEvent cloneWith(long sequenceNumber)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   161
                throws CloneNotSupportedException {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   162
            LogEvent cloned = (LogEvent)super.clone();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   163
            cloned.sequenceNumber = sequenceNumber;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   164
            return cloned;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   165
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   166
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   167
        public static LogEvent of(long sequenceNumber,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   168
                boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   169
                sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   170
                String key, Throwable thrown, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   171
            return LogEvent.of(sequenceNumber, isLoggable, name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   172
                    null, null, level, bundle, key,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   173
                    thrown, params);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   174
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   175
        public static LogEvent of(long sequenceNumber,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   176
                boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   177
                sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   178
                Supplier<String> supplier, Throwable thrown, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   179
            return LogEvent.of(sequenceNumber, isLoggable, name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   180
                    null, null, level, bundle, supplier,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   181
                    thrown, params);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   182
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   183
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   184
        public static LogEvent of(long sequenceNumber,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   185
                boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   186
                String className, String methodName,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   187
                sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   188
                String key, Throwable thrown, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   189
            LogEvent evt = new LogEvent(sequenceNumber);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   190
            evt.loggerName = name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   191
            evt.level = level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   192
            evt.args = params;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   193
            evt.bundle = bundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   194
            evt.thrown = thrown;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   195
            evt.msg = key;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   196
            evt.isLoggable = isLoggable;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   197
            evt.className = className;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   198
            evt.methodName = methodName;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   199
            return evt;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   200
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   201
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   202
        public static LogEvent of(boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   203
                String className, String methodName,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   204
                sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   205
                String key, Throwable thrown, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   206
            return LogEvent.of(sequencer.getAndIncrement(), isLoggable, name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   207
                    className, methodName, level, bundle, key, thrown, params);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   208
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   209
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   210
        public static LogEvent of(long sequenceNumber,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   211
                boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   212
                String className, String methodName,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   213
                sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   214
                Supplier<String> supplier, Throwable thrown, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   215
            LogEvent evt = new LogEvent(sequenceNumber);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   216
            evt.loggerName = name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   217
            evt.level = level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   218
            evt.args = params;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   219
            evt.bundle = bundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   220
            evt.thrown = thrown;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   221
            evt.supplier = supplier;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   222
            evt.isLoggable = isLoggable;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   223
            evt.className = className;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   224
            evt.methodName = methodName;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   225
            return evt;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   226
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   227
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   228
        public static LogEvent of(boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   229
                String className, String methodName,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   230
                sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   231
                Supplier<String> supplier, Throwable thrown, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   232
            return LogEvent.of(sequencer.getAndIncrement(), isLoggable, name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   233
                    className, methodName, level, bundle, supplier, thrown, params);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   234
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   235
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   236
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   237
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   238
    public static class LogProducerFinder extends LoggerFinder {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   239
        static final RuntimePermission LOGGERFINDER_PERMISSION =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   240
                new RuntimePermission("loggerFinder");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   241
        final ConcurrentHashMap<String, LoggerImpl> system = new ConcurrentHashMap<>();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   242
        final ConcurrentHashMap<String, LoggerImpl> user = new ConcurrentHashMap<>();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   243
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   244
        public class LoggerImpl implements Logger, PlatformLogger.Bridge {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   245
            private final String name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   246
            private sun.util.logging.PlatformLogger.Level level = sun.util.logging.PlatformLogger.Level.INFO;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   247
            private sun.util.logging.PlatformLogger.Level OFF = sun.util.logging.PlatformLogger.Level.OFF;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   248
            private sun.util.logging.PlatformLogger.Level FINE = sun.util.logging.PlatformLogger.Level.FINE;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   249
            private sun.util.logging.PlatformLogger.Level FINER = sun.util.logging.PlatformLogger.Level.FINER;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   250
            private sun.util.logging.PlatformLogger.Level FINEST = sun.util.logging.PlatformLogger.Level.FINEST;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   251
            private sun.util.logging.PlatformLogger.Level CONFIG = sun.util.logging.PlatformLogger.Level.CONFIG;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   252
            private sun.util.logging.PlatformLogger.Level INFO = sun.util.logging.PlatformLogger.Level.INFO;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   253
            private sun.util.logging.PlatformLogger.Level WARNING = sun.util.logging.PlatformLogger.Level.WARNING;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   254
            private sun.util.logging.PlatformLogger.Level SEVERE = sun.util.logging.PlatformLogger.Level.SEVERE;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   255
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   256
            public LoggerImpl(String name) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   257
                this.name = name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   258
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   259
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   260
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   261
            public String getName() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   262
                return name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   263
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   264
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   265
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   266
            public boolean isLoggable(Level level) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   267
                return this.level != OFF && this.level.intValue() <= level.getSeverity();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   268
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   269
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   270
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   271
            public void log(Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   272
                    String key, Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   273
                throw new UnsupportedOperationException();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   274
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   275
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   276
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   277
            public void log(Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   278
                    String format, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   279
                throw new UnsupportedOperationException();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   280
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   281
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   282
            void log(LogEvent event) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   283
                eventQueue.add(event);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   284
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   285
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   286
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   287
            public void log(Level level, Supplier<String> msgSupplier) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   288
                throw new UnsupportedOperationException();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   289
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   290
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   291
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   292
            public void log(Level level, Supplier<String> msgSupplier,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   293
                            Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   294
                throw new UnsupportedOperationException();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   295
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   296
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   297
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   298
            public void log(sun.util.logging.PlatformLogger.Level level, String msg) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   299
                log(LogEvent.of(isLoggable(level), name, null, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   300
                        level, null, msg, null, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   301
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   302
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   303
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   304
            public void log(sun.util.logging.PlatformLogger.Level level,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   305
                    Supplier<String> msgSupplier) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   306
                log(LogEvent.of(isLoggable(level), name, null, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   307
                        level, null, msgSupplier, null, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   308
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   309
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   310
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   311
            public void log(sun.util.logging.PlatformLogger.Level level, String msg,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   312
                    Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   313
                log(LogEvent.of(isLoggable(level), name, null, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   314
                        level, null, msg, null, params));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   315
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   316
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   317
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   318
            public void log(sun.util.logging.PlatformLogger.Level level, String msg,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   319
                    Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   320
                log(LogEvent.of(isLoggable(level), name, null, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   321
                        level, null, msg, thrown, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   322
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   323
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   324
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   325
            public void log(sun.util.logging.PlatformLogger.Level level, Throwable thrown,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   326
                    Supplier<String> msgSupplier) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   327
                log(LogEvent.of(isLoggable(level), name, null, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   328
                        level, null, msgSupplier, thrown, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   329
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   330
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   331
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   332
            public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   333
                    String sourceMethod, String msg) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   334
                log(LogEvent.of(isLoggable(level), name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   335
                        sourceClass, sourceMethod,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   336
                        level, null, msg, null, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   337
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   338
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   339
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   340
            public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   341
                    String sourceMethod, Supplier<String> msgSupplier) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   342
                log(LogEvent.of(isLoggable(level), name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   343
                        sourceClass, sourceMethod,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   344
                        level, null, msgSupplier, null, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   345
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   346
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   347
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   348
            public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   349
                    String sourceMethod, String msg, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   350
                log(LogEvent.of(isLoggable(level), name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   351
                        sourceClass, sourceMethod,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   352
                        level, null, msg, null, params));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   353
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   354
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   355
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   356
            public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   357
                    String sourceMethod, String msg, Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   358
                log(LogEvent.of(isLoggable(level), name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   359
                        sourceClass, sourceMethod,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   360
                        level, null, msg, thrown, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   361
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   362
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   363
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   364
            public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   365
                    String sourceMethod, Throwable thrown,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   366
                    Supplier<String> msgSupplier) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   367
                log(LogEvent.of(isLoggable(level), name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   368
                        sourceClass, sourceMethod,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   369
                        level, null, msgSupplier, thrown, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   370
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   371
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   372
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   373
            public void logrb(sun.util.logging.PlatformLogger.Level level, String sourceClass,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   374
                    String sourceMethod, ResourceBundle bundle, String msg,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   375
                    Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   376
                log(LogEvent.of(isLoggable(level), name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   377
                        sourceClass, sourceMethod,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   378
                        level, bundle, msg, null, params));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   379
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   380
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   381
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   382
            public void logrb(sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   383
                    String msg, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   384
                log(LogEvent.of(isLoggable(level), name, null, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   385
                        level, bundle, msg, null, params));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   386
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   387
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   388
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   389
            public void logrb(sun.util.logging.PlatformLogger.Level level, String sourceClass,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   390
                    String sourceMethod, ResourceBundle bundle, String msg,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   391
                    Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   392
                log(LogEvent.of(isLoggable(level), name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   393
                        sourceClass, sourceMethod,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   394
                        level, bundle, msg, thrown, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   395
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   396
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   397
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   398
            public void logrb(sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   399
                    String msg, Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   400
                log(LogEvent.of(isLoggable(level), name, null, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   401
                        level, bundle, msg, thrown, (Object[])null));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   402
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   403
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   404
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   405
            public boolean isLoggable(sun.util.logging.PlatformLogger.Level level) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   406
                return this.level != OFF && level.intValue()
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   407
                        >= this.level.intValue();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   408
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   409
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   410
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   411
            public boolean isEnabled() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   412
                return this.level != OFF;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   413
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   414
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   415
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   416
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   417
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   418
        @Override
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 36237
diff changeset
   419
        public Logger getLogger(String name, Module caller) {
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   420
            SecurityManager sm = System.getSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   421
            if (sm != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   422
                sm.checkPermission(LOGGERFINDER_PERMISSION);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   423
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   424
            PrivilegedAction<ClassLoader> pa = () -> caller.getClassLoader();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   425
            ClassLoader callerLoader = AccessController.doPrivileged(pa);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   426
            if (callerLoader == null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   427
                return system.computeIfAbsent(name, (n) -> new LoggerImpl(n));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   428
            } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   429
                return user.computeIfAbsent(name, (n) -> new LoggerImpl(n));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   430
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   431
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   432
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   433
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   434
    static final sun.util.logging.PlatformLogger.Level[] julLevels = {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   435
        sun.util.logging.PlatformLogger.Level.ALL,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   436
        sun.util.logging.PlatformLogger.Level.FINEST,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   437
        sun.util.logging.PlatformLogger.Level.FINER,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   438
        sun.util.logging.PlatformLogger.Level.FINE,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   439
        sun.util.logging.PlatformLogger.Level.CONFIG,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   440
        sun.util.logging.PlatformLogger.Level.INFO,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   441
        sun.util.logging.PlatformLogger.Level.WARNING,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   442
        sun.util.logging.PlatformLogger.Level.SEVERE,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   443
        sun.util.logging.PlatformLogger.Level.OFF,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   444
    };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   445
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   446
    public static class MyBundle extends ResourceBundle {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   447
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   448
        final ConcurrentHashMap map = new ConcurrentHashMap();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   449
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   450
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   451
        protected Object handleGetObject(String key) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   452
            if (key.contains(" (translated)")) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   453
                throw new RuntimeException("Unexpected key: " + key);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   454
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   455
            return map.computeIfAbsent(key, k -> k + " (translated)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   456
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   457
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   458
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   459
        public Enumeration<String> getKeys() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   460
            return Collections.enumeration(map.keySet());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   461
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   462
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   463
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   464
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   465
    public static class MyHandler extends Handler {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   466
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   467
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   468
        public java.util.logging.Level getLevel() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   469
            return java.util.logging.Level.ALL;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   470
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   471
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   472
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   473
        public void publish(LogRecord record) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   474
            eventQueue.add(LogEvent.of(sequencer.getAndIncrement(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   475
                    true, record.getLoggerName(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   476
                    record.getSourceClassName(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   477
                    record.getSourceMethodName(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   478
                    PlatformLogger.Level.valueOf(record.getLevel().getName()),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   479
                    record.getResourceBundle(), record.getMessage(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   480
                    record.getThrown(), record.getParameters()));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   481
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   482
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   483
        public void flush() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   484
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   485
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   486
        public void close() throws SecurityException {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   487
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   488
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   489
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   490
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   491
    public static class MyLoggerBundle extends MyBundle {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   492
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   493
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   494
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   495
    static enum TestCases {NOSECURITY, NOPERMISSIONS, WITHPERMISSIONS};
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   496
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   497
    static void setSecurityManager() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   498
        if (System.getSecurityManager() == null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   499
            Policy.setPolicy(new SimplePolicy(allowControl, allowAccess, allowAll));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   500
            System.setSecurityManager(new SecurityManager());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   501
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   502
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   503
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   504
    public static void main(String[] args) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   505
        if (args.length == 0)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   506
            args = new String[] {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   507
                //"NOSECURITY",
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   508
                "NOPERMISSIONS",
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   509
                "WITHPERMISSIONS"
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   510
            };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   511
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   512
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   513
        Stream.of(args).map(TestCases::valueOf).forEach((testCase) -> {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   514
            LoggerFinder provider;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   515
            switch (testCase) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   516
                case NOSECURITY:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   517
                    System.out.println("\n*** Without Security Manager\n");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   518
                    provider = LoggerFinder.getLoggerFinder();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   519
                    test(provider, true);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   520
                    System.out.println("Tetscase count: " + sequencer.get());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   521
                    break;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   522
                case NOPERMISSIONS:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   523
                    System.out.println("\n*** With Security Manager, without permissions\n");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   524
                    setSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   525
                    try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   526
                        provider = LoggerFinder.getLoggerFinder();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   527
                        throw new RuntimeException("Expected exception not raised");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   528
                    } catch (AccessControlException x) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   529
                        if (!LOGGERFINDER_PERMISSION.equals(x.getPermission())) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   530
                            throw new RuntimeException("Unexpected permission check", x);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   531
                        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   532
                        final boolean control = allowControl.get().get();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   533
                        try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   534
                            allowControl.get().set(true);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   535
                            provider = LoggerFinder.getLoggerFinder();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   536
                        } finally {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   537
                            allowControl.get().set(control);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   538
                        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   539
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   540
                    test(provider, false);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   541
                    System.out.println("Tetscase count: " + sequencer.get());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   542
                    break;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   543
                case WITHPERMISSIONS:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   544
                    System.out.println("\n*** With Security Manager, with access permission\n");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   545
                    setSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   546
                    final boolean control = allowControl.get().get();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   547
                    try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   548
                        allowControl.get().set(true);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   549
                        provider = LoggerFinder.getLoggerFinder();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   550
                    } finally {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   551
                        allowControl.get().set(control);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   552
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   553
                    final boolean access = allowAccess.get().get();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   554
                    try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   555
                        allowAccess.get().set(true);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   556
                        test(provider, true);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   557
                    } finally {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   558
                        allowAccess.get().set(access);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   559
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   560
                    break;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   561
                default:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   562
                    throw new RuntimeException("Unknown test case: " + testCase);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   563
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   564
        });
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   565
        System.out.println("\nPASSED: Tested " + sequencer.get() + " cases.");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   566
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   567
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   568
    public static void test(LoggerFinder provider, boolean hasRequiredPermissions) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   569
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   570
        final Map<PlatformLogger, String> loggerDescMap = new HashMap<>();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   571
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   572
        PlatformLogger sysLogger1 = null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   573
        try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   574
            sysLogger1 = PlatformLogger.getLogger("foo");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   575
            loggerDescMap.put(sysLogger1, "PlatformLogger.getLogger(\"foo\")");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   576
            if (!hasRequiredPermissions) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   577
                throw new RuntimeException("Managed to obtain a system logger without permission");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   578
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   579
        } catch (AccessControlException acx) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   580
            if (hasRequiredPermissions) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   581
                throw new RuntimeException("Unexpected security exception: ", acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   582
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   583
            if (!acx.getPermission().equals(SimplePolicy.ACCESS_LOGGING)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   584
                throw new RuntimeException("Unexpected permission in exception: " + acx, acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   585
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   586
            final boolean old = allowAccess.get().get();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   587
            allowAccess.get().set(true);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   588
            try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   589
                sysLogger1 = PlatformLogger.getLogger("foo");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   590
                loggerDescMap.put(sysLogger1, "PlatformLogger.getLogger(\"foo\")");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   591
            } finally {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   592
                allowAccess.get().set(old);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   593
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   594
            System.out.println("Got expected exception for system logger: " + acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   595
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   596
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   597
        final LogProducerFinder.LoggerImpl sysSink;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   598
        boolean old = allowControl.get().get();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   599
        allowControl.get().set(true);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   600
        try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   601
           sysSink = LogProducerFinder.LoggerImpl.class.cast(
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 36237
diff changeset
   602
                        provider.getLogger("foo", Thread.class.getModule()));
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   603
        } finally {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   604
            allowControl.get().set(old);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   605
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   606
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   607
        testLogger(provider, loggerDescMap, "foo", null, sysLogger1, sysSink);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   608
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   609
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   610
    public static class Foo {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   611
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   612
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   613
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   614
    static void verbose(String msg) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   615
       if (VERBOSE) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   616
           System.out.println(msg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   617
       }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   618
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   619
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   620
    static void checkLogEvent(LoggerFinder provider, String desc,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   621
            LogEvent expected) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   622
        LogEvent actual =  eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   623
        if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   624
            throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   625
                    + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   626
                    + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   627
        } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   628
            verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   629
                    + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   630
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   631
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   632
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   633
    static void checkLogEvent(LoggerFinder provider, String desc,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   634
            LogEvent expected, boolean expectNotNull) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   635
        LogEvent actual =  eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   636
        if (actual == null && !expectNotNull) return;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   637
        if (actual != null && !expectNotNull) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   638
            throw new RuntimeException("Unexpected log event found for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   639
                + "\n\tgot: " + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   640
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   641
        if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   642
            throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   643
                    + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   644
                    + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   645
        } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   646
            verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   647
                    + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   648
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   649
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   650
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   651
    static void setLevel( LogProducerFinder.LoggerImpl sink,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   652
            sun.util.logging.PlatformLogger.Level loggerLevel) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   653
        sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   654
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   655
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   656
    // Calls the methods defined on LogProducer and verify the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   657
    // parameters received by the underlying LogProducerFinder.LoggerImpl
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   658
    // logger.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   659
    private static void testLogger(LoggerFinder provider,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   660
            Map<PlatformLogger, String> loggerDescMap,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   661
            String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   662
            ResourceBundle loggerBundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   663
            PlatformLogger logger,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   664
            LogProducerFinder.LoggerImpl sink) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   665
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   666
        System.out.println("Testing " + loggerDescMap.get(logger) + " [" + logger +"]");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   667
        final sun.util.logging.PlatformLogger.Level OFF = sun.util.logging.PlatformLogger.Level.OFF;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   668
        final sun.util.logging.PlatformLogger.Level ALL = sun.util.logging.PlatformLogger.Level.OFF;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   669
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   670
        Foo foo = new Foo();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   671
        String fooMsg = foo.toString();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   672
        System.out.println("\tlogger.log(messageLevel, fooMsg)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   673
        System.out.println("\tlogger.<level>(fooMsg)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   674
        for (sun.util.logging.PlatformLogger.Level loggerLevel : julLevels) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   675
            setLevel(sink, loggerLevel);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   676
            for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   677
                if (messageLevel == ALL || messageLevel == OFF) continue;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   678
                LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   679
                        LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   680
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   681
                            loggerLevel != OFF && messageLevel.intValue() >= loggerLevel.intValue(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   682
                            name, messageLevel, loggerBundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   683
                            fooMsg, (Throwable)null, (Object[])null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   684
                String desc2 = "logger." + messageLevel.toString().toLowerCase()
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   685
                        + "(fooMsg): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   686
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   687
                if (messageLevel == sun.util.logging.PlatformLogger.Level.FINEST) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   688
                    logger.finest(fooMsg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   689
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   690
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.FINER) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   691
                    logger.finer(fooMsg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   692
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   693
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.FINE) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   694
                    logger.fine(fooMsg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   695
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   696
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.CONFIG) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   697
                    logger.config(fooMsg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   698
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   699
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.INFO) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   700
                    logger.info(fooMsg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   701
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   702
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.WARNING) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   703
                    logger.warning(fooMsg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   704
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   705
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.SEVERE) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   706
                    logger.severe(fooMsg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   707
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   708
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   709
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   710
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   711
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   712
        String format = "two params [{1} {2}]";
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   713
        Object arg1 = foo;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   714
        Object arg2 = fooMsg;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   715
        System.out.println("\tlogger.log(messageLevel, format, arg1, arg2)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   716
        for (sun.util.logging.PlatformLogger.Level loggerLevel : julLevels) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   717
            setLevel(sink, loggerLevel);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   718
            for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   719
                if (messageLevel == ALL || messageLevel == OFF) continue;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   720
                LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   721
                        LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   722
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   723
                            loggerLevel != OFF && messageLevel.intValue() >= loggerLevel.intValue(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   724
                            name, messageLevel, loggerBundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   725
                            format, (Throwable)null, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   726
                String desc2 = "logger." + messageLevel.toString().toLowerCase()
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   727
                        + "(format, foo, fooMsg): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   728
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   729
                if (messageLevel == sun.util.logging.PlatformLogger.Level.FINEST) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   730
                    logger.finest(format, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   731
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   732
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.FINER) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   733
                    logger.finer(format, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   734
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   735
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.FINE) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   736
                    logger.fine(format, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   737
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   738
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.CONFIG) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   739
                    logger.config(format, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   740
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   741
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.INFO) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   742
                    logger.info(format, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   743
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   744
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.WARNING) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   745
                    logger.warning(format, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   746
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   747
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.SEVERE) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   748
                    logger.severe(format, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   749
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   750
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   751
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   752
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   753
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   754
        Throwable thrown = new Exception("OK: log me!");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   755
        System.out.println("\tlogger.log(messageLevel, fooMsg, thrown)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   756
        for (sun.util.logging.PlatformLogger.Level loggerLevel : julLevels) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   757
            setLevel(sink, loggerLevel);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   758
            for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   759
                if (messageLevel == ALL || messageLevel == OFF) continue;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   760
                LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   761
                        LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   762
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   763
                            loggerLevel != OFF && messageLevel.intValue() >= loggerLevel.intValue(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   764
                            name, messageLevel, loggerBundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   765
                            fooMsg, thrown, (Object[])null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   766
                String desc2 = "logger." + messageLevel.toString().toLowerCase()
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   767
                        + "(fooMsg, thrown): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   768
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   769
                if (messageLevel == sun.util.logging.PlatformLogger.Level.FINEST) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   770
                    logger.finest(fooMsg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   771
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   772
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.FINER) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   773
                    logger.finer(fooMsg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   774
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   775
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.FINE) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   776
                    logger.fine(fooMsg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   777
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   778
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.CONFIG) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   779
                    logger.config(fooMsg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   780
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   781
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.INFO) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   782
                    logger.info(fooMsg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   783
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   784
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.WARNING) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   785
                    logger.warning(fooMsg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   786
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   787
                } else if (messageLevel == sun.util.logging.PlatformLogger.Level.SEVERE) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   788
                    logger.severe(fooMsg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   789
                    checkLogEvent(provider, desc2, expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   790
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   791
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   792
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   793
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   794
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   795
    final static class PermissionsBuilder {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   796
        final Permissions perms;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   797
        public PermissionsBuilder() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   798
            this(new Permissions());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   799
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   800
        public PermissionsBuilder(Permissions perms) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   801
            this.perms = perms;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   802
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   803
        public PermissionsBuilder add(Permission p) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   804
            perms.add(p);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   805
            return this;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   806
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   807
        public PermissionsBuilder addAll(PermissionCollection col) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   808
            if (col != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   809
                for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   810
                    perms.add(e.nextElement());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   811
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   812
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   813
            return this;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   814
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   815
        public Permissions toPermissions() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   816
            final PermissionsBuilder builder = new PermissionsBuilder();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   817
            builder.addAll(perms);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   818
            return builder.perms;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   819
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   820
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   821
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   822
    public static class SimplePolicy extends Policy {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   823
        final static RuntimePermission CONTROL = LOGGERFINDER_PERMISSION;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   824
        final static RuntimePermission ACCESS_LOGGER = new RuntimePermission("accessClassInPackage.jdk.internal.logger");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   825
        final static RuntimePermission ACCESS_LOGGING = new RuntimePermission("accessClassInPackage.sun.util.logging");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   826
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   827
        final Permissions permissions;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   828
        final Permissions allPermissions;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   829
        final ThreadLocal<AtomicBoolean> allowControl;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   830
        final ThreadLocal<AtomicBoolean> allowAccess;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   831
        final ThreadLocal<AtomicBoolean> allowAll;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   832
        public SimplePolicy(ThreadLocal<AtomicBoolean> allowControl,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   833
                ThreadLocal<AtomicBoolean> allowAccess,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   834
                ThreadLocal<AtomicBoolean> allowAll) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   835
            this.allowControl = allowControl;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   836
            this.allowAccess = allowAccess;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   837
            this.allowAll = allowAll;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   838
            permissions = new Permissions();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   839
            allPermissions = new PermissionsBuilder()
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   840
                    .add(new java.security.AllPermission())
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   841
                    .toPermissions();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   842
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   843
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   844
        Permissions getPermissions() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   845
            if (allowControl.get().get() || allowAccess.get().get() || allowAll.get().get()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   846
                PermissionsBuilder builder =  new PermissionsBuilder()
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   847
                        .addAll(permissions);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   848
                if (allowControl.get().get()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   849
                    builder.add(CONTROL);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   850
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   851
                if (allowAccess.get().get()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   852
                    builder.add(ACCESS_LOGGER);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   853
                    builder.add(ACCESS_LOGGING);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   854
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   855
                if (allowAll.get().get()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   856
                    builder.addAll(allPermissions);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   857
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   858
                return builder.toPermissions();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   859
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   860
            return permissions;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   861
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   862
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   863
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   864
        public boolean implies(ProtectionDomain domain, Permission permission) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   865
            return getPermissions().implies(permission);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   866
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   867
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   868
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   869
        public PermissionCollection getPermissions(CodeSource codesource) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   870
            return new PermissionsBuilder().addAll(getPermissions()).toPermissions();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   871
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   872
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   873
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   874
        public PermissionCollection getPermissions(ProtectionDomain domain) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   875
            return new PermissionsBuilder().addAll(getPermissions()).toPermissions();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   876
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   877
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   878
}