Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/System/LoggerFinder/internal/BaseDefaultLoggerFinderTest/BaseLoggerFinder.java
41161 views
1
/*
2
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import jdk.internal.logger.DefaultLoggerFinder;
25
import jdk.internal.logger.SimpleConsoleLogger;
26
import sun.util.logging.PlatformLogger;
27
28
import java.lang.System.Logger;
29
import java.lang.System.Logger.Level;
30
import java.security.AccessController;
31
import java.security.PrivilegedAction;
32
33
public class BaseLoggerFinder extends DefaultLoggerFinder
34
implements BaseDefaultLoggerFinderTest.TestLoggerFinder {
35
36
public BaseLoggerFinder() {
37
if (fails.get()) {
38
throw new RuntimeException("Simulate exception while loading provider");
39
}
40
}
41
42
@Override
43
public void setLevel(Logger logger, Level level, Module caller) {
44
PrivilegedAction<Void> pa = () -> {
45
setLevel(logger, PlatformLogger.toPlatformLevel(level), caller);
46
return null;
47
};
48
AccessController.doPrivileged(pa);
49
}
50
51
@Override
52
public void setLevel(Logger logger, PlatformLogger.Level level, Module caller) {
53
PrivilegedAction<Logger> pa = () -> demandLoggerFor(logger.getName(), caller);
54
Logger impl = AccessController.doPrivileged(pa);
55
SimpleConsoleLogger.class.cast(impl)
56
.getLoggerConfiguration()
57
.setPlatformLevel(level);
58
}
59
60
@Override
61
public PlatformLogger.Bridge asPlatformLoggerBridge(Logger logger) {
62
PrivilegedAction<PlatformLogger.Bridge> pa = () ->
63
PlatformLogger.Bridge.convert(logger);
64
return AccessController.doPrivileged(pa);
65
}
66
67
}
68
69
70