author | martin |
Mon, 05 Feb 2018 20:20:35 -0800 | |
changeset 48770 | a0475462616e |
parent 48674 | e2a7856edfba |
permissions | -rw-r--r-- |
48674
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
1 |
/* |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
4 |
* |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
8 |
* |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
14 |
* |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
18 |
* |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
22 |
*/ |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
23 |
import java.io.ByteArrayOutputStream; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
24 |
import java.io.IOException; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
25 |
import java.io.OutputStream; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
26 |
import java.io.PrintStream; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
27 |
import java.nio.file.Files; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
28 |
import java.nio.file.Path; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
29 |
import java.nio.file.Paths; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
30 |
import java.nio.file.StandardCopyOption; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
31 |
import java.util.Collections; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
32 |
import java.util.Enumeration; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
33 |
import java.util.List; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
34 |
import java.util.Objects; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
35 |
import java.util.concurrent.ConcurrentHashMap; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
36 |
import java.util.concurrent.ConcurrentMap; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
37 |
import java.util.logging.Handler; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
38 |
import java.util.logging.Level; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
39 |
import java.util.logging.LogManager; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
40 |
import java.util.logging.Logger; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
41 |
import java.util.stream.Collectors; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
42 |
import java.util.stream.Stream; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
43 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
44 |
/** |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
45 |
* @test |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
46 |
* @bug 8191033 |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
47 |
* @build custom.DotHandler custom.Handler |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
48 |
* @run main/othervm -Dlogging.properties=badlogging.properties -Dclz=1custom.DotHandler BadRootLoggerHandlers CUSTOM |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
49 |
* @run main/othervm -Dlogging.properties=badlogging.properties -Dclz=1custom.DotHandler BadRootLoggerHandlers DEFAULT |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
50 |
* @run main/othervm -Dlogging.properties=badglobal.properties -Dclz=1custom.GlobalHandler BadRootLoggerHandlers CUSTOM |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
51 |
* @run main/othervm -Dlogging.properties=badglobal.properties -Dclz=1custom.GlobalHandler BadRootLoggerHandlers DEFAULT |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
52 |
* @run main/othervm/java.security.policy==test.policy -Dlogging.properties=badlogging.properties -Dclz=1custom.DotHandler BadRootLoggerHandlers CUSTOM |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
53 |
* @run main/othervm/java.security.policy==test.policy -Dlogging.properties=badlogging.properties -Dclz=1custom.DotHandler BadRootLoggerHandlers DEFAULT |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
54 |
* @run main/othervm/java.security.policy==test.policy -Dlogging.properties=badglobal.properties -Dclz=1custom.GlobalHandler BadRootLoggerHandlers CUSTOM |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
55 |
* @run main/othervm/java.security.policy==test.policy -Dlogging.properties=badglobal.properties -Dclz=1custom.GlobalHandler BadRootLoggerHandlers DEFAULT |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
56 |
* @author danielfuchs |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
57 |
*/ |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
58 |
public class BadRootLoggerHandlers { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
59 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
60 |
public static final Path SRC_DIR = |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
61 |
Paths.get(System.getProperty("test.src", "src")); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
62 |
public static final Path USER_DIR = |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
63 |
Paths.get(System.getProperty("user.dir", ".")); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
64 |
public static final Path CONFIG_FILE = Paths.get( |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
65 |
Objects.requireNonNull(System.getProperty("logging.properties"))); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
66 |
public static final String BAD_HANDLER_NAME = |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
67 |
Objects.requireNonNull(System.getProperty("clz")); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
68 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
69 |
static enum TESTS { CUSTOM, DEFAULT} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
70 |
public static final class CustomLogManager extends LogManager { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
71 |
final ConcurrentMap<String, Logger> loggers = new ConcurrentHashMap<>(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
72 |
@Override |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
73 |
public boolean addLogger(Logger logger) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
74 |
return loggers.putIfAbsent(logger.getName(), logger) == null; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
75 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
76 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
77 |
@Override |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
78 |
public Enumeration<String> getLoggerNames() { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
79 |
return Collections.enumeration(loggers.keySet()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
80 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
81 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
82 |
@Override |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
83 |
public Logger getLogger(String name) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
84 |
return loggers.get(name); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
85 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
86 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
87 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
88 |
public static class SystemErr extends OutputStream { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
89 |
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
90 |
final OutputStream wrapped; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
91 |
public SystemErr(OutputStream out) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
92 |
this.wrapped = out; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
93 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
94 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
95 |
@Override |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
96 |
public void write(int b) throws IOException { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
97 |
baos.write(b); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
98 |
wrapped.write(b); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
99 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
100 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
101 |
public void close() throws IOException { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
102 |
flush(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
103 |
super.close(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
104 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
105 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
106 |
public void flush() throws IOException { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
107 |
super.flush(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
108 |
wrapped.flush(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
109 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
110 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
111 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
112 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
113 |
// Uncomment this to run the test on Java 8. Java 8 does not have |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
114 |
// List.of(...) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
115 |
// static final class List { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
116 |
// static <T> java.util.List<T> of(T... items) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
117 |
// return Collections.unmodifiableList(Arrays.asList(items)); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
118 |
// } |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
119 |
// } |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
120 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
121 |
public static void main(String[] args) throws IOException { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
122 |
Path initialProps = SRC_DIR.resolve(CONFIG_FILE); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
123 |
Path loggingProps = USER_DIR.resolve(CONFIG_FILE); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
124 |
if (args.length != 1) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
125 |
throw new IllegalArgumentException("expected (only) one of " + List.of(TESTS.values())); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
126 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
127 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
128 |
TESTS test = TESTS.valueOf(args[0]); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
129 |
System.setProperty("java.util.logging.config.file", loggingProps.toString()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
130 |
if (test == TESTS.CUSTOM) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
131 |
System.setProperty("java.util.logging.manager", CustomLogManager.class.getName()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
132 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
133 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
134 |
Files.copy(initialProps, loggingProps, StandardCopyOption.REPLACE_EXISTING); |
48770
a0475462616e
8196768: RootLoggerHandlers fails when source tree is read-only
martin
parents:
48674
diff
changeset
|
135 |
loggingProps.toFile().setWritable(true); |
48674
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
136 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
137 |
SystemErr err = new SystemErr(System.err); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
138 |
System.setErr(new PrintStream(err)); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
139 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
140 |
System.out.println("Root level is: " + Logger.getLogger("").getLevel()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
141 |
if (Logger.getLogger("").getLevel() != Level.INFO) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
142 |
throw new RuntimeException("Expected root level INFO, got: " |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
143 |
+ Logger.getLogger("").getLevel()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
144 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
145 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
146 |
Class<? extends LogManager> logManagerClass = |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
147 |
LogManager.getLogManager().getClass(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
148 |
Class<? extends LogManager> expectedClass = |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
149 |
test == TESTS.CUSTOM ? CustomLogManager.class : LogManager.class; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
150 |
if (logManagerClass != expectedClass) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
151 |
throw new RuntimeException("Bad class for log manager: " + logManagerClass |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
152 |
+ " expected " + expectedClass + " for " + test); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
153 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
154 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
155 |
if (test == TESTS.DEFAULT) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
156 |
// Verify that we have two handlers. One was configured with |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
157 |
// handlers=custom.Handler, the other with |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
158 |
// .handlers=custom.DotHandler |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
159 |
// Verify that exactly one of the two handlers is a custom.Handler |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
160 |
// Verify that exactly one of the two handlers is a custom.DotHandler |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
161 |
// Verify that the two handlers have an id of '1' |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
162 |
checkHandlers(Logger.getLogger(""), |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
163 |
Logger.getLogger("").getHandlers(), |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
164 |
1L, |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
165 |
custom.Handler.class, |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
166 |
custom.DotHandler.class); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
167 |
} else { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
168 |
// Verify that we have one handler, configured with |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
169 |
// handlers=custom.Handler. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
170 |
// Verify that it is a custom.Handler |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
171 |
// Verify that the handler have an id of '1' |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
172 |
checkHandlers(Logger.getLogger(""), |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
173 |
Logger.getLogger("").getHandlers(), |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
174 |
1L, |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
175 |
custom.Handler.class); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
176 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
177 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
178 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
179 |
// DEFAULT: The log message "hi" should appear twice on the console. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
180 |
// CUSTOM: The log message "hi" should appear twice on the console. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
181 |
// We don't check that. This is just for log analysis in case |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
182 |
// of test failure. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
183 |
Logger.getAnonymousLogger().info("hi (" + test +")"); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
184 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
185 |
// Change the root logger level to FINE in the properties file |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
186 |
// and reload the configuration. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
187 |
Files.write(loggingProps, |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
188 |
Files.lines(initialProps) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
189 |
.map((s) -> s.replace("INFO", "FINE")) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
190 |
.collect(Collectors.toList())); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
191 |
LogManager.getLogManager().readConfiguration(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
192 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
193 |
System.out.println("Root level is: " + Logger.getLogger("").getLevel()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
194 |
if (Logger.getLogger("").getLevel() != Level.FINE) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
195 |
throw new RuntimeException("Expected root level FINE, got: " |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
196 |
+ Logger.getLogger("").getLevel()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
197 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
198 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
199 |
// Verify that we have now only one handler, configured with |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
200 |
// handlers=custom.Handler, and that the other configured with |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
201 |
// .handlers=custom.DotHandler was ignored. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
202 |
// Verify that the handler is a custom.Handler |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
203 |
// Verify that the handler has an id of '2' |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
204 |
checkHandlers(Logger.getLogger(""), |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
205 |
Logger.getLogger("").getHandlers(), |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
206 |
2L, |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
207 |
custom.Handler.class); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
208 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
209 |
// The log message "there" should appear only once on the console. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
210 |
// We don't check that. This is just for log analysis in case |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
211 |
// of test failure. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
212 |
Logger.getAnonymousLogger().info("there!"); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
213 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
214 |
// Change the root logger level to FINER in the properties file |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
215 |
// and reload the configuration. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
216 |
Files.write(loggingProps, |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
217 |
Files.lines(initialProps) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
218 |
.map((s) -> s.replace("INFO", "FINER")) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
219 |
.collect(Collectors.toList())); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
220 |
LogManager.getLogManager().readConfiguration(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
221 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
222 |
System.out.println("Root level is: " + Logger.getLogger("").getLevel()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
223 |
if (Logger.getLogger("").getLevel() != Level.FINER) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
224 |
throw new RuntimeException("Expected root level FINER, got: " |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
225 |
+ Logger.getLogger("").getLevel()); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
226 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
227 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
228 |
// Verify that we have only one handler, configured with |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
229 |
// handlers=custom.Handler, and that the other configured with |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
230 |
// .handlers=custom.DotHandler was ignored. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
231 |
// Verify that the handler is a custom.Handler |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
232 |
// Verify that the handler has an id of '3' |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
233 |
checkHandlers(Logger.getLogger(""), |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
234 |
Logger.getLogger("").getHandlers(), |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
235 |
3L, |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
236 |
custom.Handler.class); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
237 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
238 |
// The log message "done" should appear only once on the console. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
239 |
// We don't check that. This is just for log analysis in case |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
240 |
// of test failure. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
241 |
Logger.getAnonymousLogger().info("done!"); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
242 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
243 |
byte[] errBytes = err.baos.toByteArray(); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
244 |
String errText = new String(errBytes); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
245 |
switch(test) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
246 |
case CUSTOM: |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
247 |
if (errText.contains("java.lang.ClassNotFoundException: " |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
248 |
+ BAD_HANDLER_NAME)) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
249 |
throw new RuntimeException("Error message found on System.err"); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
250 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
251 |
System.out.println("OK: ClassNotFoundException error message not found for " + test); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
252 |
break; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
253 |
case DEFAULT: |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
254 |
if (!errText.contains("java.lang.ClassNotFoundException: " |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
255 |
+ BAD_HANDLER_NAME)) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
256 |
throw new RuntimeException("Error message not found on System.err"); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
257 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
258 |
System.err.println("OK: ClassNotFoundException error message found for " + test); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
259 |
break; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
260 |
default: |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
261 |
throw new InternalError("unknown test case: " + test); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
262 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
263 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
264 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
265 |
static void checkHandlers(Logger logger, Handler[] handlers, Long expectedID, Class<?>... clz) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
266 |
// Verify that we have the expected number of handlers. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
267 |
if (Stream.of(handlers).count() != clz.length) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
268 |
throw new RuntimeException("Expected " + clz.length + " handlers, got: " |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
269 |
+ List.of(logger.getHandlers())); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
270 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
271 |
for (Class<?> cl : clz) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
272 |
// Verify that the handlers are of the expected class. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
273 |
// For each class, we should have exactly one handler |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
274 |
// of that class. |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
275 |
if (Stream.of(handlers) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
276 |
.map(Object::getClass) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
277 |
.filter(cl::equals) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
278 |
.count() != 1) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
279 |
throw new RuntimeException("Expected one " + cl +", got: " |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
280 |
+ List.of(logger.getHandlers())); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
281 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
282 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
283 |
// Verify that all handlers have the expected ID |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
284 |
if (Stream.of(logger.getHandlers()) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
285 |
.map(BadRootLoggerHandlers::getId) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
286 |
.filter(expectedID::equals) |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
287 |
.count() != clz.length) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
288 |
throw new RuntimeException("Expected ids to be " + expectedID + ", got: " |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
289 |
+ List.of(logger.getHandlers())); |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
290 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
291 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
292 |
|
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
293 |
static long getId(Handler h) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
294 |
if (h instanceof custom.Handler) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
295 |
return ((custom.Handler)h).id; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
296 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
297 |
if (h instanceof custom.DotHandler) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
298 |
return ((custom.DotHandler)h).id; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
299 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
300 |
if (h instanceof custom.GlobalHandler) { |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
301 |
return ((custom.GlobalHandler)h).id; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
302 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
303 |
return -1; |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
304 |
} |
e2a7856edfba
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff
changeset
|
305 |
} |