author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 37672 | 03684934dc09 |
permissions | -rw-r--r-- |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1 |
/* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
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 sun.util.logging.PlatformLogger; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
46 |
import java.lang.System.LoggerFinder; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
47 |
import java.lang.System.Logger; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
48 |
import java.lang.System.Logger.Level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
49 |
import java.util.stream.Stream; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
50 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
51 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
52 |
* @test |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
53 |
* @bug 8140364 |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
54 |
* @summary JDK implementation specific unit test for JDK internal artifacts. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
55 |
* Tests a naive implementation of System.Logger, and in particular |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
56 |
* the default mapping provided by PlatformLogger.Bridge. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
57 |
* @modules java.base/sun.util.logging java.base/jdk.internal.logger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
58 |
* @build CustomSystemClassLoader BaseLoggerBridgeTest |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
59 |
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BaseLoggerBridgeTest NOSECURITY |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
60 |
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BaseLoggerBridgeTest NOPERMISSIONS |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
61 |
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BaseLoggerBridgeTest WITHPERMISSIONS |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
62 |
* @author danielfuchs |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
63 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
64 |
public class BaseLoggerBridgeTest { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
65 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
66 |
static final RuntimePermission LOGGERFINDER_PERMISSION = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
67 |
new RuntimePermission("loggerFinder"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
68 |
final static AtomicLong sequencer = new AtomicLong(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
69 |
final static boolean VERBOSE = false; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
70 |
// whether the implementation of Logger try to do a best |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
71 |
// effort for logp... Our base logger finder stub doesn't |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
72 |
// support logp, and thus the logp() implementation comes from |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
73 |
// LoggerWrapper - which does a best effort. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
74 |
static final boolean BEST_EFFORT_FOR_LOGP = true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
75 |
static final ThreadLocal<AtomicBoolean> allowControl = new ThreadLocal<AtomicBoolean>() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
76 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
77 |
protected AtomicBoolean initialValue() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
78 |
return new AtomicBoolean(false); |
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 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
81 |
static final ThreadLocal<AtomicBoolean> allowAccess = new ThreadLocal<AtomicBoolean>() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
82 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
83 |
protected AtomicBoolean initialValue() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
84 |
return new AtomicBoolean(false); |
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 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
87 |
static final ThreadLocal<AtomicBoolean> allowAll = new ThreadLocal<AtomicBoolean>() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
88 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
89 |
protected AtomicBoolean initialValue() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
90 |
return new AtomicBoolean(false); |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
94 |
static final Class<?> providerClass; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
95 |
static { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
96 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
97 |
providerClass = ClassLoader.getSystemClassLoader().loadClass("BaseLoggerBridgeTest$BaseLoggerFinder"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
98 |
} catch (ClassNotFoundException ex) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
99 |
throw new ExceptionInInitializerError(ex); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
100 |
} |
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 |
static final sun.util.logging.PlatformLogger.Level[] julLevels = { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
104 |
sun.util.logging.PlatformLogger.Level.ALL, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
105 |
sun.util.logging.PlatformLogger.Level.FINEST, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
106 |
sun.util.logging.PlatformLogger.Level.FINER, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
107 |
sun.util.logging.PlatformLogger.Level.FINE, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
108 |
sun.util.logging.PlatformLogger.Level.CONFIG, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
109 |
sun.util.logging.PlatformLogger.Level.INFO, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
110 |
sun.util.logging.PlatformLogger.Level.WARNING, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
111 |
sun.util.logging.PlatformLogger.Level.SEVERE, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
112 |
sun.util.logging.PlatformLogger.Level.OFF, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
113 |
}; |
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 |
static final Level[] mappedLevels = { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
116 |
Level.ALL, // ALL |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
117 |
Level.TRACE, // FINEST |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
118 |
Level.TRACE, // FINER |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
119 |
Level.DEBUG, // FINE |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
120 |
Level.DEBUG, // CONFIG |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
121 |
Level.INFO, // INFO |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
122 |
Level.WARNING, // WARNING |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
123 |
Level.ERROR, // SEVERE |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
124 |
Level.OFF, // OFF |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
125 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
126 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
127 |
final static Map<sun.util.logging.PlatformLogger.Level, Level> julToSpiMap; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
128 |
static { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
129 |
Map<sun.util.logging.PlatformLogger.Level, Level> map = new HashMap<>(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
130 |
if (mappedLevels.length != julLevels.length) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
131 |
throw new ExceptionInInitializerError("Array lengths differ" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
132 |
+ "\n\tjulLevels=" + Arrays.deepToString(julLevels) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
133 |
+ "\n\tmappedLevels=" + Arrays.deepToString(mappedLevels)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
134 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
135 |
for (int i=0; i<julLevels.length; i++) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
136 |
map.put(julLevels[i], mappedLevels[i]); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
137 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
138 |
julToSpiMap = Collections.unmodifiableMap(map); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
139 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
140 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
141 |
public static class MyBundle extends ResourceBundle { |
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 |
final ConcurrentHashMap<String,String> map = new ConcurrentHashMap<>(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
144 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
145 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
146 |
protected Object handleGetObject(String key) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
147 |
if (key.contains(" (translated)")) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
148 |
throw new RuntimeException("Unexpected key: " + key); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
149 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
150 |
return map.computeIfAbsent(key, k -> k + " (translated)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
151 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
152 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
153 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
154 |
public Enumeration<String> getKeys() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
155 |
return Collections.enumeration(map.keySet()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
156 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
157 |
|
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 |
public static class MyLoggerBundle extends MyBundle { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
160 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
161 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
162 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
163 |
public static interface TestLoggerFinder { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
164 |
final ConcurrentHashMap<String, LoggerImpl> system = new ConcurrentHashMap<>(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
165 |
final ConcurrentHashMap<String, LoggerImpl> user = new ConcurrentHashMap<>(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
166 |
public Queue<LogEvent> eventQueue = new ArrayBlockingQueue<>(128); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
167 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
168 |
public static final class LogEvent implements Cloneable { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
169 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
170 |
public LogEvent() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
171 |
this(sequencer.getAndIncrement()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
172 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
173 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
174 |
LogEvent(long sequenceNumber) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
175 |
this.sequenceNumber = sequenceNumber; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
176 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
177 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
178 |
boolean callSupplier = false; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
179 |
long sequenceNumber; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
180 |
boolean isLoggable; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
181 |
String loggerName; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
182 |
Level level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
183 |
ResourceBundle bundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
184 |
Throwable thrown; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
185 |
Object[] args; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
186 |
Supplier<String> supplier; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
187 |
String msg; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
188 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
189 |
Object[] toArray(boolean callSupplier) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
190 |
return new Object[] { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
191 |
sequenceNumber, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
192 |
isLoggable, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
193 |
loggerName, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
194 |
level, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
195 |
bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
196 |
thrown, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
197 |
args, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
198 |
callSupplier && supplier != null ? supplier.get() : supplier, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
199 |
msg, |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
203 |
boolean callSupplier(Object obj) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
204 |
return callSupplier || ((LogEvent)obj).callSupplier; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
205 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
206 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
207 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
208 |
public String toString() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
209 |
return Arrays.deepToString(toArray(false)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
210 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
211 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
212 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
213 |
public boolean equals(Object obj) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
214 |
return obj instanceof LogEvent |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
215 |
&& Objects.deepEquals(toArray(callSupplier(obj)), ((LogEvent)obj).toArray(callSupplier(obj))); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
216 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
217 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
218 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
219 |
public int hashCode() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
220 |
return Objects.hash(toArray(true)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
221 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
222 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
223 |
public LogEvent cloneWith(long sequenceNumber) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
224 |
throws CloneNotSupportedException { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
225 |
LogEvent cloned = (LogEvent)super.clone(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
226 |
cloned.sequenceNumber = sequenceNumber; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
227 |
return cloned; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
228 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
229 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
230 |
public static LogEvent of(boolean isLoggable, String name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
231 |
Level level, ResourceBundle bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
232 |
String key, Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
233 |
LogEvent evt = new LogEvent(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
234 |
evt.isLoggable = isLoggable; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
235 |
evt.loggerName = name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
236 |
evt.level = level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
237 |
evt.args = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
238 |
evt.bundle = bundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
239 |
evt.thrown = thrown; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
240 |
evt.supplier = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
241 |
evt.msg = key; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
242 |
return evt; |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
245 |
public static LogEvent of(boolean isLoggable, String name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
246 |
Level level, Throwable thrown, Supplier<String> supplier) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
247 |
LogEvent evt = new LogEvent(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
248 |
evt.isLoggable = isLoggable; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
249 |
evt.loggerName = name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
250 |
evt.level = level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
251 |
evt.args = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
252 |
evt.bundle = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
253 |
evt.thrown = thrown; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
254 |
evt.supplier = supplier; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
255 |
evt.msg = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
256 |
return evt; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
257 |
} |
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 |
public static LogEvent of(boolean isLoggable, String name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
260 |
Level level, ResourceBundle bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
261 |
String key, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
262 |
LogEvent evt = new LogEvent(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
263 |
evt.isLoggable = isLoggable; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
264 |
evt.loggerName = name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
265 |
evt.level = level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
266 |
evt.args = params; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
267 |
evt.bundle = bundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
268 |
evt.thrown = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
269 |
evt.supplier = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
270 |
evt.msg = key; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
271 |
return evt; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
272 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
273 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
274 |
public static LogEvent of(long sequenceNumber, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
275 |
boolean isLoggable, String name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
276 |
Level level, ResourceBundle bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
277 |
String key, Supplier<String> supplier, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
278 |
Throwable thrown, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
279 |
LogEvent evt = new LogEvent(sequenceNumber); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
280 |
evt.loggerName = name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
281 |
evt.level = level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
282 |
evt.args = params; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
283 |
evt.bundle = bundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
284 |
evt.thrown = thrown; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
285 |
evt.supplier = supplier; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
286 |
evt.msg = key; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
287 |
evt.isLoggable = isLoggable; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
288 |
return evt; |
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 |
public static LogEvent ofp(boolean callSupplier, LogEvent evt) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
292 |
evt.callSupplier = callSupplier; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
293 |
return evt; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
294 |
} |
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 |
public class LoggerImpl implements Logger { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
298 |
private final String name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
299 |
private Level level = Level.INFO; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
300 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
301 |
public LoggerImpl(String name) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
302 |
this.name = name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
303 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
304 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
305 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
306 |
public String getName() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
307 |
return name; |
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 boolean isLoggable(Level level) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
312 |
return this.level != Level.OFF && this.level.getSeverity() <= level.getSeverity(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
313 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
314 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
315 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
316 |
public void log(Level level, ResourceBundle bundle, String key, Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
317 |
log(LogEvent.of(isLoggable(level), this.name, level, bundle, key, thrown)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
318 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
319 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
320 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
321 |
public void log(Level level, ResourceBundle bundle, String format, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
322 |
log(LogEvent.of(isLoggable(level), name, level, bundle, format, params)); |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
325 |
void log(LogEvent event) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
326 |
eventQueue.add(event); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
327 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
328 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
329 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
330 |
public void log(Level level, Supplier<String> msgSupplier) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
331 |
log(LogEvent.of(isLoggable(level), name, level, null, msgSupplier)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
332 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
333 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
334 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
335 |
public void log(Level level, Supplier<String> msgSupplier, Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
336 |
log(LogEvent.of(isLoggable(level), name, level, thrown, msgSupplier)); |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
340 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
341 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
342 |
|
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
343 |
public Logger getLogger(String name, Module caller); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
344 |
public Logger getLocalizedLogger(String name, ResourceBundle bundle, Module caller); |
33875
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 |
public static class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
348 |
static final RuntimePermission LOGGERFINDER_PERMISSION = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
349 |
new RuntimePermission("loggerFinder"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
350 |
@Override |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
351 |
public Logger getLogger(String name, Module caller) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
352 |
SecurityManager sm = System.getSecurityManager(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
353 |
if (sm != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
354 |
sm.checkPermission(LOGGERFINDER_PERMISSION); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
355 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
356 |
PrivilegedAction<ClassLoader> pa = () -> caller.getClassLoader(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
357 |
ClassLoader callerLoader = AccessController.doPrivileged(pa); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
358 |
if (callerLoader == null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
359 |
return system.computeIfAbsent(name, (n) -> new LoggerImpl(n)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
360 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
361 |
return user.computeIfAbsent(name, (n) -> new LoggerImpl(n)); |
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 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
364 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
365 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
366 |
static PlatformLogger.Bridge convert(Logger logger) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
367 |
boolean old = allowAll.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
368 |
allowAccess.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
369 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
370 |
return PlatformLogger.Bridge.convert(logger); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
371 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
372 |
allowAccess.get().set(old); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
373 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
374 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
375 |
|
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
376 |
static Logger getLogger(String name, Module caller) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
377 |
boolean old = allowAll.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
378 |
allowAccess.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
379 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
380 |
return jdk.internal.logger.LazyLoggers.getLogger(name, caller); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
381 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
382 |
allowAccess.get().set(old); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
383 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
384 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
385 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
386 |
static enum TestCases {NOSECURITY, NOPERMISSIONS, WITHPERMISSIONS}; |
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 |
static void setSecurityManager() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
389 |
if (System.getSecurityManager() == null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
390 |
// Ugly test hack: preload the resources needed by String.format |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
391 |
// We need to do that before setting the security manager |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
392 |
// because our implementation of CustomSystemClassLoader |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
393 |
// doesn't have the required permission. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
394 |
System.out.println(String.format("debug: %s", "Setting security manager")); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
395 |
Policy.setPolicy(new SimplePolicy(allowControl, allowAccess, allowAll)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
396 |
System.setSecurityManager(new SecurityManager()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
397 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
398 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
399 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
400 |
public static void main(String[] args) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
401 |
if (args.length == 0) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
402 |
args = new String[] { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
403 |
"NOSECURITY", |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
404 |
"NOPERMISSIONS", |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
405 |
"WITHPERMISSIONS" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
406 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
407 |
|
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 |
Stream.of(args).map(TestCases::valueOf).forEach((testCase) -> { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
410 |
TestLoggerFinder provider; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
411 |
switch (testCase) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
412 |
case NOSECURITY: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
413 |
System.out.println("\n*** Without Security Manager\n"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
414 |
provider = TestLoggerFinder.class.cast(LoggerFinder.getLoggerFinder()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
415 |
test(provider, true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
416 |
System.out.println("Tetscase count: " + sequencer.get()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
417 |
break; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
418 |
case NOPERMISSIONS: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
419 |
System.out.println("\n*** With Security Manager, without permissions\n"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
420 |
setSecurityManager(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
421 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
422 |
provider = TestLoggerFinder.class.cast(LoggerFinder.getLoggerFinder()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
423 |
throw new RuntimeException("Expected exception not raised"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
424 |
} catch (AccessControlException x) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
425 |
if (!LOGGERFINDER_PERMISSION.equals(x.getPermission())) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
426 |
throw new RuntimeException("Unexpected permission check", x); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
427 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
428 |
final boolean control = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
429 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
430 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
431 |
provider = TestLoggerFinder.class.cast(LoggerFinder.getLoggerFinder()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
432 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
433 |
allowControl.get().set(control); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
434 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
435 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
436 |
test(provider, false); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
437 |
System.out.println("Tetscase count: " + sequencer.get()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
438 |
break; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
439 |
case WITHPERMISSIONS: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
440 |
System.out.println("\n*** With Security Manager, with control permission\n"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
441 |
setSecurityManager(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
442 |
final boolean control = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
443 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
444 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
445 |
provider = TestLoggerFinder.class.cast(LoggerFinder.getLoggerFinder()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
446 |
test(provider, true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
447 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
448 |
allowControl.get().set(control); |
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 |
break; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
451 |
default: |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
452 |
throw new RuntimeException("Unknown test case: " + testCase); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
453 |
} |
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 |
System.out.println("\nPASSED: Tested " + sequencer.get() + " cases."); |
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 |
public static void test(TestLoggerFinder provider, boolean hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
459 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
460 |
ResourceBundle loggerBundle = ResourceBundle.getBundle(MyLoggerBundle.class.getName()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
461 |
final Map<Object, String> loggerDescMap = new HashMap<>(); |
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 |
TestLoggerFinder.LoggerImpl appSink = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
465 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
466 |
appSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerBridgeTest.class.getModule())); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
467 |
if (!hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
468 |
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
|
469 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
470 |
} catch (AccessControlException acx) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
471 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
472 |
throw new RuntimeException("Unexpected security exception: ", acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
473 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
474 |
if (!acx.getPermission().equals(LOGGERFINDER_PERMISSION)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
475 |
throw new RuntimeException("Unexpected permission in exception: " + acx, acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
476 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
477 |
System.out.println("Got expected exception for logger: " + acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
478 |
boolean old = allowControl.get().get(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
479 |
allowControl.get().set(true); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
480 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
481 |
appSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerBridgeTest.class.getModule())); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
482 |
} finally { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
483 |
allowControl.get().set(old); |
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 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
486 |
|
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 |
TestLoggerFinder.LoggerImpl sysSink = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
489 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
490 |
sysSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class.getModule())); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
491 |
if (!hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
492 |
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
|
493 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
494 |
} catch (AccessControlException acx) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
495 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
496 |
throw new RuntimeException("Unexpected security exception: ", acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
497 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
498 |
if (!acx.getPermission().equals(LOGGERFINDER_PERMISSION)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
499 |
throw new RuntimeException("Unexpected permission in exception: " + acx, acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
500 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
501 |
System.out.println("Got expected exception for system logger: " + acx); |
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 |
if (hasRequiredPermissions && appSink == sysSink) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
504 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
505 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
506 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
507 |
if (provider.system.contains(appSink)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
508 |
throw new RuntimeException("app logger in system map"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
509 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
510 |
if (!provider.user.contains(appSink)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
511 |
throw new RuntimeException("app logger not in appplication map"); |
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 |
if (hasRequiredPermissions && provider.user.contains(sysSink)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
514 |
throw new RuntimeException("sys logger in appplication map"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
515 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
516 |
if (hasRequiredPermissions && !provider.system.contains(sysSink)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
517 |
throw new RuntimeException("sys logger not in system map"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
518 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
519 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
520 |
Logger appLogger1 = System.getLogger("foo"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
521 |
loggerDescMap.put(appLogger1, "System.getLogger(\"foo\")"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
522 |
PlatformLogger.Bridge bridge = convert(appLogger1); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
523 |
loggerDescMap.putIfAbsent(bridge, "PlatformLogger.Bridge.convert(System.getLogger(\"foo\"))"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
524 |
testLogger(provider, loggerDescMap, "foo", null, bridge, appSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
525 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
526 |
Logger sysLogger1 = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
527 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
528 |
sysLogger1 = getLogger("foo", Thread.class.getModule()); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
529 |
loggerDescMap.put(sysLogger1, |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
530 |
"jdk.internal.logger.LazyLoggers.getLogger(\"foo\", Thread.class.getModule())"); |
33875
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 |
if (!hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
533 |
// check that the provider would have thrown an exception |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
534 |
provider.getLogger("foo", Thread.class.getModule()); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
535 |
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
|
536 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
537 |
} catch (AccessControlException acx) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
538 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
539 |
throw new RuntimeException("Unexpected security exception: ", acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
540 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
541 |
if (!acx.getPermission().equals(LOGGERFINDER_PERMISSION)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
542 |
throw new RuntimeException("Unexpected permission in exception: " + acx, acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
543 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
544 |
System.out.println("Got expected exception for system logger: " + acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
545 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
546 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
547 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
548 |
// if we don't have permissions sysSink will be null. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
549 |
testLogger(provider, loggerDescMap, "foo", null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
550 |
PlatformLogger.Bridge.convert(sysLogger1), sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
551 |
} |
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 |
Logger appLogger2 = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
554 |
System.getLogger("foo", loggerBundle); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
555 |
loggerDescMap.put(appLogger2, "System.getLogger(\"foo\", loggerBundle)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
556 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
557 |
if (appLogger2 == appLogger1) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
558 |
throw new RuntimeException("identical loggers"); |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
561 |
if (provider.system.contains(appLogger2)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
562 |
throw new RuntimeException("localized app logger in system map"); |
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 |
if (provider.user.contains(appLogger2)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
565 |
throw new RuntimeException("localized app logger in appplication map"); |
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 |
testLogger(provider, loggerDescMap, "foo", loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
569 |
PlatformLogger.Bridge.convert(appLogger2), appSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
570 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
571 |
Logger sysLogger2 = null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
572 |
try { |
37672
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
573 |
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule()); |
03684934dc09
8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents:
33875
diff
changeset
|
574 |
loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
575 |
if (!hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
576 |
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
|
577 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
578 |
} catch (AccessControlException acx) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
579 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
580 |
throw new RuntimeException("Unexpected security exception: ", acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
581 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
582 |
if (!acx.getPermission().equals(LOGGERFINDER_PERMISSION)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
583 |
throw new RuntimeException("Unexpected permission in exception: " + acx, acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
584 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
585 |
System.out.println("Got expected exception for localized system logger: " + acx); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
586 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
587 |
if (hasRequiredPermissions && appLogger2 == sysLogger2) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
588 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
589 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
590 |
if (hasRequiredPermissions && sysLogger2 == sysLogger1) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
591 |
throw new RuntimeException("identical loggers"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
592 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
593 |
if (hasRequiredPermissions && provider.user.contains(sysLogger2)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
594 |
throw new RuntimeException("localized sys logger in appplication map"); |
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 |
if (hasRequiredPermissions && provider.system.contains(sysLogger2)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
597 |
throw new RuntimeException("localized sys logger not in system map"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
598 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
599 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
600 |
if (hasRequiredPermissions) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
601 |
// if we don't have permissions sysSink will be null. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
602 |
testLogger(provider, loggerDescMap, "foo", loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
603 |
PlatformLogger.Bridge.convert(sysLogger2), sysSink); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
604 |
} |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
608 |
public static class Foo { |
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 |
} |
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 |
static void verbose(String msg) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
613 |
if (VERBOSE) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
614 |
System.out.println(msg); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
615 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
616 |
} |
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 |
static void checkLogEvent(TestLoggerFinder provider, String desc, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
619 |
TestLoggerFinder.LogEvent expected) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
620 |
TestLoggerFinder.LogEvent actual = provider.eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
621 |
if (!Objects.equals(expected, actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
622 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
623 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
624 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
625 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
626 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
627 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
628 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
629 |
} |
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 |
static void checkLogEvent(TestLoggerFinder provider, String desc, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
632 |
TestLoggerFinder.LogEvent expected, boolean expectNotNull) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
633 |
TestLoggerFinder.LogEvent actual = provider.eventQueue.poll(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
634 |
if (actual == null && !expectNotNull) return; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
635 |
if (actual != null && !expectNotNull) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
636 |
throw new RuntimeException("Unexpected log event found for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
637 |
+ "\n\tgot: " + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
638 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
639 |
if (!expected.equals(actual)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
640 |
throw new RuntimeException("mismatch for " + desc |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
641 |
+ "\n\texpected=" + expected |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
642 |
+ "\n\t actual=" + actual); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
643 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
644 |
verbose("Got expected results for " |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
645 |
+ desc + "\n\t" + expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
646 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
647 |
} |
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 |
static Supplier<String> logpMessage(ResourceBundle bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
650 |
String className, String methodName, Supplier<String> msg) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
651 |
if (BEST_EFFORT_FOR_LOGP && bundle == null |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
652 |
&& (className != null || methodName != null)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
653 |
final String cName = className == null ? "" : className; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
654 |
final String mName = methodName == null ? "" : methodName; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
655 |
return () -> String.format("[%s %s] %s", cName, mName, msg.get()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
656 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
657 |
return msg; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
658 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
659 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
660 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
661 |
static String logpMessage(ResourceBundle bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
662 |
String className, String methodName, String msg) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
663 |
if (BEST_EFFORT_FOR_LOGP && bundle == null |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
664 |
&& (className != null || methodName != null)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
665 |
final String cName = className == null ? "" : className; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
666 |
final String mName = methodName == null ? "" : methodName; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
667 |
return String.format("[%s %s] %s", cName, mName, msg == null ? "" : msg); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
668 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
669 |
return msg; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
670 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
671 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
672 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
673 |
// Calls the methods defined on LogProducer and verify the |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
674 |
// parameters received by the underlying TestLoggerFinder.LoggerImpl |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
675 |
// logger. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
676 |
private static void testLogger(TestLoggerFinder provider, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
677 |
Map<Object, String> loggerDescMap, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
678 |
String name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
679 |
ResourceBundle loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
680 |
PlatformLogger.Bridge logger, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
681 |
TestLoggerFinder.LoggerImpl sink) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
682 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
683 |
if (loggerDescMap.get(logger) == null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
684 |
throw new RuntimeException("Test bug: Missing description"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
685 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
686 |
System.out.println("Testing " + loggerDescMap.get(logger) +" [" + logger + "]"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
687 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
688 |
Foo foo = new Foo(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
689 |
String fooMsg = foo.toString(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
690 |
System.out.println("\tlogger.log(messageLevel, fooMsg)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
691 |
System.out.println("\tlogger.<level>(fooMsg)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
692 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
693 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
694 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
695 |
String desc = "logger.log(messageLevel, fooMsg): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
696 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
697 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
698 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
699 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
700 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
701 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
702 |
name, expectedMessageLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
703 |
fooMsg, null, (Throwable)null, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
704 |
logger.log(messageLevel, fooMsg); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
705 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
706 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
707 |
} |
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 |
Supplier<String> supplier = new Supplier<String>() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
710 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
711 |
public String get() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
712 |
return this.toString(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
713 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
714 |
}; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
715 |
System.out.println("\tlogger.log(messageLevel, supplier)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
716 |
System.out.println("\tlogger.<level>(supplier)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
717 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
718 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
719 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
720 |
String desc = "logger.log(messageLevel, supplier): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
721 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
722 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
723 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
724 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
725 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
726 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
727 |
name, expectedMessageLevel, (ResourceBundle) null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
728 |
null, supplier, (Throwable)null, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
729 |
logger.log(messageLevel, supplier); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
730 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
731 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
732 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
733 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
734 |
String format = "two params [{1} {2}]"; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
735 |
Object arg1 = foo; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
736 |
Object arg2 = fooMsg; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
737 |
System.out.println("\tlogger.log(messageLevel, format, arg1, arg2)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
738 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
739 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
740 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
741 |
String desc = "logger.log(messageLevel, format, foo, fooMsg): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
742 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
743 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
744 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
745 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
746 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
747 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
748 |
name, expectedMessageLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
749 |
format, null, (Throwable)null, arg1, arg2); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
750 |
logger.log(messageLevel, format, arg1, arg2); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
751 |
checkLogEvent(provider, desc, expected); |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
755 |
Throwable thrown = new Exception("OK: log me!"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
756 |
System.out.println("\tlogger.log(messageLevel, fooMsg, thrown)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
757 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
758 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
759 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
760 |
String desc = "logger.log(messageLevel, fooMsg, thrown): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
761 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
762 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
763 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
764 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
765 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
766 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
767 |
name, expectedMessageLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
768 |
fooMsg, null, thrown, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
769 |
logger.log(messageLevel, fooMsg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
770 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
771 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
772 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
773 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
774 |
System.out.println("\tlogger.log(messageLevel, thrown, supplier)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
775 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
776 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
777 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
778 |
String desc = "logger.log(messageLevel, thrown, supplier): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
779 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
780 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
781 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
782 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
783 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
784 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
785 |
name, expectedMessageLevel, (ResourceBundle)null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
786 |
null, supplier, thrown, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
787 |
logger.log(messageLevel, thrown, supplier); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
788 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
789 |
} |
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 |
String sourceClass = "blah.Blah"; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
793 |
String sourceMethod = "blih"; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
794 |
System.out.println("\tlogger.logp(messageLevel, sourceClass, sourceMethod, fooMsg)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
795 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
796 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
797 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
798 |
String desc = "logger.logp(messageLevel, sourceClass, sourceMethod, fooMsg): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
799 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
800 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
801 |
boolean isLoggable = loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
802 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
803 |
isLoggable || loggerBundle != null && BEST_EFFORT_FOR_LOGP? |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
804 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
805 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
806 |
isLoggable, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
807 |
name, expectedMessageLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
808 |
logpMessage(loggerBundle, sourceClass, sourceMethod, fooMsg), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
809 |
null, (Throwable)null, (Object[]) null) : null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
810 |
logger.logp(messageLevel, sourceClass, sourceMethod, fooMsg); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
811 |
checkLogEvent(provider, desc, expected); |
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 |
} |
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 |
System.out.println("\tlogger.logp(messageLevel, sourceClass, sourceMethod, supplier)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
816 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
817 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
818 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
819 |
String desc = "logger.logp(messageLevel, sourceClass, sourceMethod, supplier): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
820 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
821 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
822 |
boolean isLoggable = loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
823 |
TestLoggerFinder.LogEvent expected = isLoggable ? |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
824 |
TestLoggerFinder.LogEvent.ofp(BEST_EFFORT_FOR_LOGP, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
825 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
826 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
827 |
isLoggable, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
828 |
name, expectedMessageLevel, null, null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
829 |
logpMessage(null, sourceClass, sourceMethod, supplier), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
830 |
(Throwable)null, (Object[]) null)) : null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
831 |
logger.logp(messageLevel, sourceClass, sourceMethod, supplier); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
832 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
833 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
834 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
835 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
836 |
System.out.println("\tlogger.logp(messageLevel, sourceClass, sourceMethod, format, arg1, arg2)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
837 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
838 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
839 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
840 |
String desc = "logger.logp(messageLevel, sourceClass, sourceMethod, format, arg1, arg2): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
841 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
842 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
843 |
boolean isLoggable = loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
844 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
845 |
isLoggable || loggerBundle != null && BEST_EFFORT_FOR_LOGP? |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
846 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
847 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
848 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
849 |
name, expectedMessageLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
850 |
logpMessage(loggerBundle, sourceClass, sourceMethod, format), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
851 |
null, (Throwable)null, arg1, arg2) : null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
852 |
logger.logp(messageLevel, sourceClass, sourceMethod, format, arg1, arg2); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
853 |
checkLogEvent(provider, desc, expected); |
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 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
856 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
857 |
System.out.println("\tlogger.logp(messageLevel, sourceClass, sourceMethod, fooMsg, thrown)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
858 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
859 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
860 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
861 |
String desc = "logger.logp(messageLevel, sourceClass, sourceMethod, fooMsg, thrown): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
862 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
863 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
864 |
boolean isLoggable = loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
865 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
866 |
isLoggable || loggerBundle != null && BEST_EFFORT_FOR_LOGP ? |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
867 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
868 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
869 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
870 |
name, expectedMessageLevel, loggerBundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
871 |
logpMessage(loggerBundle, sourceClass, sourceMethod, fooMsg), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
872 |
null, thrown, (Object[])null) : null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
873 |
logger.logp(messageLevel, sourceClass, sourceMethod, fooMsg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
874 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
875 |
} |
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 |
System.out.println("\tlogger.logp(messageLevel, sourceClass, sourceMethod, thrown, supplier)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
879 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
880 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
881 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
882 |
String desc = "logger.logp(messageLevel, sourceClass, sourceMethod, thrown, supplier): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
883 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
884 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
885 |
boolean isLoggable = loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
886 |
TestLoggerFinder.LogEvent expected = isLoggable ? |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
887 |
TestLoggerFinder.LogEvent.ofp(BEST_EFFORT_FOR_LOGP, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
888 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
889 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
890 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
891 |
name, expectedMessageLevel, null, null, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
892 |
logpMessage(null, sourceClass, sourceMethod, supplier), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
893 |
thrown, (Object[])null)) : null; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
894 |
logger.logp(messageLevel, sourceClass, sourceMethod, thrown, supplier); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
895 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
896 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
897 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
898 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
899 |
ResourceBundle bundle = ResourceBundle.getBundle(MyBundle.class.getName()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
900 |
System.out.println("\tlogger.logrb(messageLevel, bundle, format, arg1, arg2)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
901 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
902 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
903 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
904 |
String desc = "logger.logrb(messageLevel, bundle, format, arg1, arg2): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
905 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
906 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
907 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
908 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
909 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
910 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
911 |
name, expectedMessageLevel, bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
912 |
format, null, (Throwable)null, arg1, arg2); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
913 |
logger.logrb(messageLevel, bundle, format, arg1, arg2); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
914 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
915 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
916 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
917 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
918 |
System.out.println("\tlogger.logrb(messageLevel, bundle, msg, thrown)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
919 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
920 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
921 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
922 |
String desc = "logger.logrb(messageLevel, bundle, msg, thrown): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
923 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
924 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
925 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
926 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
927 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
928 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
929 |
name, expectedMessageLevel, bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
930 |
fooMsg, null, thrown, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
931 |
logger.logrb(messageLevel, bundle, fooMsg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
932 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
933 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
934 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
935 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
936 |
System.out.println("\tlogger.logrb(messageLevel, sourceClass, sourceMethod, bundle, format, arg1, arg2)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
937 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
938 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
939 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
940 |
String desc = "logger.logrb(messageLevel, sourceClass, sourceMethod, bundle, format, arg1, arg2): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
941 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
942 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
943 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
944 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
945 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
946 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
947 |
name, expectedMessageLevel, bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
948 |
format, null, (Throwable)null, arg1, arg2); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
949 |
logger.logrb(messageLevel, sourceClass, sourceMethod, bundle, format, arg1, arg2); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
950 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
951 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
952 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
953 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
954 |
System.out.println("\tlogger.logrb(messageLevel, sourceClass, sourceMethod, bundle, msg, thrown)"); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
955 |
for (Level loggerLevel : Level.values()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
956 |
sink.level = loggerLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
957 |
for (sun.util.logging.PlatformLogger.Level messageLevel :julLevels) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
958 |
String desc = "logger.logrb(messageLevel, sourceClass, sourceMethod, bundle, msg, thrown): loggerLevel=" |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
959 |
+ loggerLevel+", messageLevel="+messageLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
960 |
Level expectedMessageLevel = julToSpiMap.get(messageLevel); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
961 |
TestLoggerFinder.LogEvent expected = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
962 |
TestLoggerFinder.LogEvent.of( |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
963 |
sequencer.get(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
964 |
loggerLevel != Level.OFF && expectedMessageLevel.compareTo(loggerLevel) >= 0, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
965 |
name, expectedMessageLevel, bundle, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
966 |
fooMsg, null, thrown, (Object[])null); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
967 |
logger.logrb(messageLevel, sourceClass, sourceMethod, bundle, fooMsg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
968 |
checkLogEvent(provider, desc, expected); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
969 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
970 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
971 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
972 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
973 |
final static class PermissionsBuilder { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
974 |
final Permissions perms; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
975 |
public PermissionsBuilder() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
976 |
this(new Permissions()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
977 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
978 |
public PermissionsBuilder(Permissions perms) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
979 |
this.perms = perms; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
980 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
981 |
public PermissionsBuilder add(Permission p) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
982 |
perms.add(p); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
983 |
return this; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
984 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
985 |
public PermissionsBuilder addAll(PermissionCollection col) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
986 |
if (col != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
987 |
for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
988 |
perms.add(e.nextElement()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
989 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
990 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
991 |
return this; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
992 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
993 |
public Permissions toPermissions() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
994 |
final PermissionsBuilder builder = new PermissionsBuilder(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
995 |
builder.addAll(perms); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
996 |
return builder.perms; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
997 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
998 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
999 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1000 |
public static class SimplePolicy extends Policy { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1001 |
final static RuntimePermission CONTROL = LOGGERFINDER_PERMISSION; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1002 |
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
|
1003 |
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
|
1004 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1005 |
final Permissions permissions; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1006 |
final Permissions allPermissions; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1007 |
final ThreadLocal<AtomicBoolean> allowControl; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1008 |
final ThreadLocal<AtomicBoolean> allowAccess; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1009 |
final ThreadLocal<AtomicBoolean> allowAll; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1010 |
public SimplePolicy(ThreadLocal<AtomicBoolean> allowControl, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1011 |
ThreadLocal<AtomicBoolean> allowAccess, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1012 |
ThreadLocal<AtomicBoolean> allowAll) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1013 |
this.allowControl = allowControl; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1014 |
this.allowAccess = allowAccess; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1015 |
this.allowAll = allowAll; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1016 |
permissions = new Permissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1017 |
allPermissions = new PermissionsBuilder() |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1018 |
.add(new java.security.AllPermission()) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1019 |
.toPermissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1020 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1021 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1022 |
Permissions getPermissions() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1023 |
if (allowControl.get().get() || allowAccess.get().get() || allowAll.get().get()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1024 |
PermissionsBuilder builder = new PermissionsBuilder() |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1025 |
.addAll(permissions); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1026 |
if (allowControl.get().get()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1027 |
builder.add(CONTROL); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1028 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1029 |
if (allowAccess.get().get()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1030 |
builder.add(ACCESS_LOGGER); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1031 |
builder.add(ACCESS_LOGGING); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1032 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1033 |
if (allowAll.get().get()) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1034 |
builder.addAll(allPermissions); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1035 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1036 |
return builder.toPermissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1037 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1038 |
return permissions; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1039 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1040 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1041 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1042 |
public boolean implies(ProtectionDomain domain, Permission permission) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1043 |
return getPermissions().implies(permission); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1044 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1045 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1046 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1047 |
public PermissionCollection getPermissions(CodeSource codesource) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1048 |
return new PermissionsBuilder().addAll(getPermissions()).toPermissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1049 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1050 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1051 |
@Override |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1052 |
public PermissionCollection getPermissions(ProtectionDomain domain) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1053 |
return new PermissionsBuilder().addAll(getPermissions()).toPermissions(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1054 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1055 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1056 |
} |