author | redestad |
Thu, 21 Apr 2016 13:39:53 +0200 | |
changeset 37593 | 824750ada3d6 |
parent 36679 | 0e6911cee995 |
child 37781 | 71ed5645f17c |
permissions | -rw-r--r-- |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
1 |
/* |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
4 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
10 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
11 |
* 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
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
13 |
* 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
|
14 |
* 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
|
15 |
* accompanied this code). |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
16 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
17 |
* 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
|
18 |
* 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
|
19 |
* 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
|
20 |
* |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
21 |
* 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
|
22 |
* 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
|
23 |
* questions. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
24 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
25 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
26 |
package jdk.internal.logger; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
27 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
28 |
import java.io.PrintStream; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
29 |
import java.io.PrintWriter; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
30 |
import java.io.StringWriter; |
34723
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
31 |
import java.lang.StackWalker.StackFrame; |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
32 |
import java.security.AccessController; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
33 |
import java.security.PrivilegedAction; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
34 |
import java.time.ZonedDateTime; |
34372 | 35 |
import java.util.Optional; |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
36 |
import java.util.ResourceBundle; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
37 |
import java.util.function.Function; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
38 |
import java.lang.System.Logger; |
34372 | 39 |
import java.util.function.Predicate; |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
40 |
import java.util.function.Supplier; |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
41 |
import sun.security.action.GetPropertyAction; |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
42 |
import sun.util.logging.PlatformLogger; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
43 |
import sun.util.logging.PlatformLogger.ConfigurableBridge.LoggerConfiguration; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
44 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
45 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
46 |
* A simple console logger to emulate the behavior of JUL loggers when |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
47 |
* in the default configuration. SimpleConsoleLoggers are also used when |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
48 |
* JUL is not present and no DefaultLoggerFinder is installed. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
49 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
50 |
public class SimpleConsoleLogger extends LoggerConfiguration |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
51 |
implements Logger, PlatformLogger.Bridge, PlatformLogger.ConfigurableBridge { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
52 |
|
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
53 |
static final Level DEFAULT_LEVEL = getDefaultLevel(); |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
54 |
static final PlatformLogger.Level DEFAULT_PLATFORM_LEVEL = |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
55 |
PlatformLogger.toPlatformLevel(DEFAULT_LEVEL); |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
56 |
|
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
57 |
static Level getDefaultLevel() { |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
36679
diff
changeset
|
58 |
String levelName = GetPropertyAction |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
36679
diff
changeset
|
59 |
.getProperty("jdk.system.logger.level", "INFO"); |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
60 |
try { |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
61 |
return Level.valueOf(levelName); |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
62 |
} catch (IllegalArgumentException iae) { |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
63 |
return Level.INFO; |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
64 |
} |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
65 |
} |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
66 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
67 |
final String name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
68 |
volatile PlatformLogger.Level level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
69 |
final boolean usePlatformLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
70 |
SimpleConsoleLogger(String name, boolean usePlatformLevel) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
71 |
this.name = name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
72 |
this.usePlatformLevel = usePlatformLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
73 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
74 |
|
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
75 |
String getSimpleFormatString() { |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
76 |
return Formatting.SIMPLE_CONSOLE_LOGGER_FORMAT; |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
77 |
} |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
78 |
|
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
79 |
PlatformLogger.Level defaultPlatformLevel() { |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
80 |
return DEFAULT_PLATFORM_LEVEL; |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
81 |
} |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
82 |
|
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
83 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
84 |
public final String getName() { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
85 |
return name; |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
88 |
private Enum<?> logLevel(PlatformLogger.Level level) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
89 |
return usePlatformLevel ? level : level.systemLevel(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
90 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
91 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
92 |
private Enum<?> logLevel(Level level) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
93 |
return usePlatformLevel ? PlatformLogger.toPlatformLevel(level) : level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
94 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
95 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
96 |
// --------------------------------------------------- |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
97 |
// From Logger |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
98 |
// --------------------------------------------------- |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
99 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
100 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
101 |
public final boolean isLoggable(Level level) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
102 |
return isLoggable(PlatformLogger.toPlatformLevel(level)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
103 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
104 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
105 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
106 |
public final void log(Level level, ResourceBundle bundle, String key, Throwable thrown) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
107 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
108 |
if (bundle != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
109 |
key = bundle.getString(key); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
110 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
111 |
publish(getCallerInfo(), logLevel(level), key, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
112 |
} |
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 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
116 |
public final void log(Level level, ResourceBundle bundle, String format, Object... params) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
117 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
118 |
if (bundle != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
119 |
format = bundle.getString(format); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
120 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
121 |
publish(getCallerInfo(), logLevel(level), format, params); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
122 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
123 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
124 |
|
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 |
// From PlatformLogger.Bridge |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
127 |
// --------------------------------------------------- |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
128 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
129 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
130 |
public final boolean isLoggable(PlatformLogger.Level level) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
131 |
final PlatformLogger.Level effectiveLevel = effectiveLevel(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
132 |
return level != PlatformLogger.Level.OFF |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
133 |
&& level.ordinal() >= effectiveLevel.ordinal(); |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
136 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
137 |
public final boolean isEnabled() { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
138 |
return level != PlatformLogger.Level.OFF; |
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 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
142 |
public final void log(PlatformLogger.Level level, String msg) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
143 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
144 |
publish(getCallerInfo(), logLevel(level), msg); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
145 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
146 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
147 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
148 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
149 |
public final void log(PlatformLogger.Level level, String msg, Throwable thrown) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
150 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
151 |
publish(getCallerInfo(), logLevel(level), msg, thrown); |
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 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
154 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
155 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
156 |
public final void log(PlatformLogger.Level level, String msg, Object... params) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
157 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
158 |
publish(getCallerInfo(), logLevel(level), msg, params); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
159 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
160 |
} |
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 |
private PlatformLogger.Level effectiveLevel() { |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
163 |
if (level == null) return defaultPlatformLevel(); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
164 |
return level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
165 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
166 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
167 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
168 |
public final PlatformLogger.Level getPlatformLevel() { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
169 |
return level; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
170 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
171 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
172 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
173 |
public final void setPlatformLevel(PlatformLogger.Level newLevel) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
174 |
level = newLevel; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
175 |
} |
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 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
178 |
public final LoggerConfiguration getLoggerConfiguration() { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
179 |
return this; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
180 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
181 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
182 |
/** |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
183 |
* Default platform logging support - output messages to System.err - |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
184 |
* equivalent to ConsoleHandler with SimpleFormatter. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
185 |
*/ |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
186 |
static PrintStream outputStream() { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
187 |
return System.err; |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
190 |
// Returns the caller's class and method's name; best effort |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
191 |
// if cannot infer, return the logger's name. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
192 |
private String getCallerInfo() { |
34372 | 193 |
Optional<StackWalker.StackFrame> frame = new CallerFinder().get(); |
194 |
if (frame.isPresent()) { |
|
195 |
return frame.get().getClassName() + " " + frame.get().getMethodName(); |
|
196 |
} else { |
|
197 |
return name; |
|
198 |
} |
|
199 |
} |
|
34370 | 200 |
|
34372 | 201 |
/* |
202 |
* CallerFinder is a stateful predicate. |
|
203 |
*/ |
|
204 |
static final class CallerFinder implements Predicate<StackWalker.StackFrame> { |
|
34723
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
205 |
private static final StackWalker WALKER; |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
206 |
static { |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
207 |
final PrivilegedAction<StackWalker> action = new PrivilegedAction<>() { |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
208 |
@Override |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
209 |
public StackWalker run() { |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
210 |
return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
211 |
} |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
212 |
}; |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
213 |
WALKER = AccessController.doPrivileged(action); |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
214 |
} |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
215 |
|
34372 | 216 |
/** |
217 |
* Returns StackFrame of the caller's frame. |
|
218 |
* @return StackFrame of the caller's frame. |
|
219 |
*/ |
|
220 |
Optional<StackWalker.StackFrame> get() { |
|
221 |
return WALKER.walk((s) -> s.filter(this).findFirst()); |
|
222 |
} |
|
223 |
||
224 |
private boolean lookingForLogger = true; |
|
225 |
/** |
|
226 |
* Returns true if we have found the caller's frame, false if the frame |
|
227 |
* must be skipped. |
|
228 |
* |
|
229 |
* @param t The frame info. |
|
230 |
* @return true if we have found the caller's frame, false if the frame |
|
231 |
* must be skipped. |
|
232 |
*/ |
|
233 |
@Override |
|
234 |
public boolean test(StackWalker.StackFrame t) { |
|
235 |
final String cname = t.getClassName(); |
|
236 |
// We should skip all frames until we have found the logger, |
|
237 |
// because these frames could be frames introduced by e.g. custom |
|
238 |
// sub classes of Handler. |
|
34370 | 239 |
if (lookingForLogger) { |
240 |
// Skip all frames until we have found the first logger frame. |
|
34372 | 241 |
lookingForLogger = !isLoggerImplFrame(cname); |
242 |
return false; |
|
34370 | 243 |
} |
34723
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
244 |
// Continue walking until we've found the relevant calling frame. |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
245 |
// Skips logging/logger infrastructure. |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
246 |
return !Formatting.isFilteredFrame(t); |
34362 | 247 |
} |
248 |
||
34372 | 249 |
private boolean isLoggerImplFrame(String cname) { |
250 |
return (cname.equals("sun.util.logging.PlatformLogger") || |
|
251 |
cname.equals("jdk.internal.logger.SimpleConsoleLogger")); |
|
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
252 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
253 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
254 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
255 |
private String getCallerInfo(String sourceClassName, String sourceMethodName) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
256 |
if (sourceClassName == null) return name; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
257 |
if (sourceMethodName == null) return sourceClassName; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
258 |
return sourceClassName + " " + sourceMethodName; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
259 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
260 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
261 |
private String toString(Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
262 |
String throwable = ""; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
263 |
if (thrown != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
264 |
StringWriter sw = new StringWriter(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
265 |
PrintWriter pw = new PrintWriter(sw); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
266 |
pw.println(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
267 |
thrown.printStackTrace(pw); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
268 |
pw.close(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
269 |
throwable = sw.toString(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
270 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
271 |
return throwable; |
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 |
private synchronized String format(Enum<?> level, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
275 |
String msg, Throwable thrown, String callerInfo) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
276 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
277 |
ZonedDateTime zdt = ZonedDateTime.now(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
278 |
String throwable = toString(thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
279 |
|
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
280 |
return String.format(getSimpleFormatString(), |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
281 |
zdt, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
282 |
callerInfo, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
283 |
name, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
284 |
level.name(), |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
285 |
msg, |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
286 |
throwable); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
287 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
288 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
289 |
// publish accepts both PlatformLogger Levels and LoggerFinder Levels. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
290 |
private void publish(String callerInfo, Enum<?> level, String msg) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
291 |
outputStream().print(format(level, msg, null, callerInfo)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
292 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
293 |
// publish accepts both PlatformLogger Levels and LoggerFinder Levels. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
294 |
private void publish(String callerInfo, Enum<?> level, String msg, Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
295 |
outputStream().print(format(level, msg, thrown, callerInfo)); |
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 |
// publish accepts both PlatformLogger Levels and LoggerFinder Levels. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
298 |
private void publish(String callerInfo, Enum<?> level, String msg, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
299 |
msg = params == null || params.length == 0 ? msg |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
300 |
: Formatting.formatMessage(msg, params); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
301 |
outputStream().print(format(level, msg, null, callerInfo)); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
302 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
303 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
304 |
public static SimpleConsoleLogger makeSimpleLogger(String name) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
305 |
return new SimpleConsoleLogger(name, false); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
306 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
307 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
308 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
309 |
public final void log(PlatformLogger.Level level, Supplier<String> msgSupplier) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
310 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
311 |
publish(getCallerInfo(), logLevel(level), msgSupplier.get()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
312 |
} |
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 |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
316 |
public final void log(PlatformLogger.Level level, Throwable thrown, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
317 |
Supplier<String> msgSupplier) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
318 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
319 |
publish(getCallerInfo(), logLevel(level), msgSupplier.get(), thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
320 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
321 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
322 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
323 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
324 |
public final void logp(PlatformLogger.Level level, String sourceClass, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
325 |
String sourceMethod, String msg) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
326 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
327 |
publish(getCallerInfo(sourceClass, sourceMethod), logLevel(level), msg); |
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 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
330 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
331 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
332 |
public final void logp(PlatformLogger.Level level, String sourceClass, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
333 |
String sourceMethod, Supplier<String> msgSupplier) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
334 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
335 |
publish(getCallerInfo(sourceClass, sourceMethod), logLevel(level), msgSupplier.get()); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
336 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
337 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
338 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
339 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
340 |
public final void logp(PlatformLogger.Level level, String sourceClass, String sourceMethod, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
341 |
String msg, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
342 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
343 |
publish(getCallerInfo(sourceClass, sourceMethod), logLevel(level), msg, params); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
344 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
345 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
346 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
347 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
348 |
public final void logp(PlatformLogger.Level level, String sourceClass, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
349 |
String sourceMethod, String msg, Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
350 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
351 |
publish(getCallerInfo(sourceClass, sourceMethod), logLevel(level), msg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
352 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
353 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
354 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
355 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
356 |
public final void logp(PlatformLogger.Level level, String sourceClass, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
357 |
String sourceMethod, Throwable thrown, Supplier<String> msgSupplier) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
358 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
359 |
publish(getCallerInfo(sourceClass, sourceMethod), logLevel(level), msgSupplier.get(), thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
360 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
361 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
362 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
363 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
364 |
public final void logrb(PlatformLogger.Level level, String sourceClass, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
365 |
String sourceMethod, ResourceBundle bundle, String key, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
366 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
367 |
String msg = bundle == null ? key : bundle.getString(key); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
368 |
publish(getCallerInfo(sourceClass, sourceMethod), logLevel(level), msg, params); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
369 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
370 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
371 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
372 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
373 |
public final void logrb(PlatformLogger.Level level, String sourceClass, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
374 |
String sourceMethod, ResourceBundle bundle, String key, Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
375 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
376 |
String msg = bundle == null ? key : bundle.getString(key); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
377 |
publish(getCallerInfo(sourceClass, sourceMethod), logLevel(level), msg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
378 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
379 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
380 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
381 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
382 |
public final void logrb(PlatformLogger.Level level, ResourceBundle bundle, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
383 |
String key, Object... params) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
384 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
385 |
String msg = bundle == null ? key : bundle.getString(key); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
386 |
publish(getCallerInfo(), logLevel(level), msg, params); |
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 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
389 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
390 |
@Override |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
391 |
public final void logrb(PlatformLogger.Level level, ResourceBundle bundle, |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
392 |
String key, Throwable thrown) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
393 |
if (isLoggable(level)) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
394 |
String msg = bundle == null ? key : bundle.getString(key); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
395 |
publish(getCallerInfo(), logLevel(level), msg, thrown); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
396 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
397 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
398 |
|
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
399 |
static final class Formatting { |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
400 |
// The default simple log format string. |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
401 |
// Used both by SimpleConsoleLogger when java.logging is not present, |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
402 |
// and by SurrogateLogger and java.util.logging.SimpleFormatter when |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
403 |
// java.logging is present. |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
404 |
static final String DEFAULT_FORMAT = |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
405 |
"%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%6$s%n"; |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
406 |
|
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
407 |
// The system property key that allows to change the default log format |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
408 |
// when java.logging is not present. This is used to control the formatting |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
409 |
// of the SimpleConsoleLogger. |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
410 |
static final String DEFAULT_FORMAT_PROP_KEY = |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
411 |
"jdk.system.logger.format"; |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
412 |
|
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
413 |
// The system property key that allows to change the default log format |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
414 |
// when java.logging is present. This is used to control the formatting |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
415 |
// of the SurrogateLogger (used before java.util.logging.LogManager is |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
416 |
// initialized) and the java.util.logging.SimpleFormatter (used after |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
417 |
// java.util.logging.LogManager is initialized). |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
418 |
static final String JUL_FORMAT_PROP_KEY = |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
419 |
"java.util.logging.SimpleFormatter.format"; |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
420 |
|
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
421 |
// The simple console logger format string |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
422 |
static final String SIMPLE_CONSOLE_LOGGER_FORMAT = |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
423 |
getSimpleFormat(DEFAULT_FORMAT_PROP_KEY, null); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
424 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
425 |
// Make it easier to wrap Logger... |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
426 |
static private final String[] skips; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
427 |
static { |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
36679
diff
changeset
|
428 |
String additionalPkgs = |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
36679
diff
changeset
|
429 |
GetPropertyAction.getProperty("jdk.logger.packages"); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
430 |
skips = additionalPkgs == null ? new String[0] : additionalPkgs.split(","); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
431 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
432 |
|
34723
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
433 |
static boolean isFilteredFrame(StackFrame st) { |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
434 |
// skip logging/logger infrastructure |
34723
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
435 |
if (System.Logger.class.isAssignableFrom(st.getDeclaringClass())) { |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
436 |
return true; |
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
437 |
} |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
438 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
439 |
// fast escape path: all the prefixes below start with 's' or 'j' and |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
440 |
// have more than 12 characters. |
34723
734a1c90ce86
8145686: SimpleConsoleLogger and LogRecord should take advantage of StackWalker to skip classes implementing System.Logger
dfuchs
parents:
34372
diff
changeset
|
441 |
final String cname = st.getClassName(); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
442 |
char c = cname.length() < 12 ? 0 : cname.charAt(0); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
443 |
if (c == 's') { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
444 |
// skip internal machinery classes |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
445 |
if (cname.startsWith("sun.util.logging.")) return true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
446 |
if (cname.startsWith("sun.rmi.runtime.Log")) return true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
447 |
} else if (c == 'j') { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
448 |
// Message delayed at Bootstrap: no need to go further up. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
449 |
if (cname.startsWith("jdk.internal.logger.BootstrapLogger$LogEvent")) return false; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
450 |
// skip public machinery classes |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
451 |
if (cname.startsWith("jdk.internal.logger.")) return true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
452 |
if (cname.startsWith("java.util.logging.")) return true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
453 |
if (cname.startsWith("java.lang.invoke.MethodHandle")) return true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
454 |
if (cname.startsWith("java.security.AccessController")) return true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
455 |
} |
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 |
// check additional prefixes if any are specified. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
458 |
if (skips.length > 0) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
459 |
for (int i=0; i<skips.length; i++) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
460 |
if (!skips[i].isEmpty() && cname.startsWith(skips[i])) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
461 |
return true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
462 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
463 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
464 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
465 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
466 |
return false; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
467 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
468 |
|
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
469 |
static String getSimpleFormat(String key, Function<String, String> defaultPropertyGetter) { |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
470 |
// Double check that 'key' is one of the expected property names: |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
471 |
// - DEFAULT_FORMAT_PROP_KEY is used to control the |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
472 |
// SimpleConsoleLogger format when java.logging is |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
473 |
// not present. |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
474 |
// - JUL_FORMAT_PROP_KEY is used when this method is called |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
475 |
// from the SurrogateLogger subclass. It is used to control the |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
476 |
// SurrogateLogger format and java.util.logging.SimpleFormatter |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
477 |
// format when java.logging is present. |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
478 |
// This method should not be called with any other key. |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
479 |
if (!DEFAULT_FORMAT_PROP_KEY.equals(key) |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
480 |
&& !JUL_FORMAT_PROP_KEY.equals(key)) { |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
481 |
throw new IllegalArgumentException("Invalid property name: " + key); |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
482 |
} |
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
483 |
|
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
484 |
// Do not use any lambda in this method. Using a lambda here causes |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
485 |
// jdk/test/java/lang/invoke/lambda/LogGeneratedClassesTest.java |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
486 |
// to fail - because that test has a testcase which somehow references |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
487 |
// PlatformLogger and counts the number of generated lambda classes. |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
36679
diff
changeset
|
488 |
String format = GetPropertyAction.getProperty(key); |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
489 |
|
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
490 |
if (format == null && defaultPropertyGetter != null) { |
36679
0e6911cee995
8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents:
34723
diff
changeset
|
491 |
format = defaultPropertyGetter.apply(key); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
492 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
493 |
if (format != null) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
494 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
495 |
// validate the user-defined format string |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
496 |
String.format(format, ZonedDateTime.now(), "", "", "", "", ""); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
497 |
} catch (IllegalArgumentException e) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
498 |
// illegal syntax; fall back to the default format |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
499 |
format = DEFAULT_FORMAT; |
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 |
} else { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
502 |
format = DEFAULT_FORMAT; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
503 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
504 |
return format; |
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 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
508 |
// Copied from java.util.logging.Formatter.formatMessage |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
509 |
static String formatMessage(String format, Object... parameters) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
510 |
// Do the formatting. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
511 |
try { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
512 |
if (parameters == null || parameters.length == 0) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
513 |
// No parameters. Just return format string. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
514 |
return format; |
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 |
// Is it a java.text style format? |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
517 |
// Ideally we could match with |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
518 |
// Pattern.compile("\\{\\d").matcher(format).find()) |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
519 |
// However the cost is 14% higher, so we cheaply check for |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
520 |
// |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
521 |
boolean isJavaTestFormat = false; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
522 |
final int len = format.length(); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
523 |
for (int i=0; i<len-2; i++) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
524 |
final char c = format.charAt(i); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
525 |
if (c == '{') { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
526 |
final int d = format.charAt(i+1); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
527 |
if (d >= '0' && d <= '9') { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
528 |
isJavaTestFormat = true; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
529 |
break; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
530 |
} |
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 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
533 |
if (isJavaTestFormat) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
534 |
return java.text.MessageFormat.format(format, parameters); |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
535 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
536 |
return format; |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
537 |
} catch (Exception ex) { |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
538 |
// Formatting failed: use format string. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
539 |
return format; |
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 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
542 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff
changeset
|
543 |
} |