Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/management/jmxremote/bootstrap/TestLogger.java
41153 views
1
/*
2
* Copyright (c) 2003, 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 java.util.logging.Logger;
25
import java.util.logging.Level;
26
27
public class TestLogger {
28
29
final Logger logger;
30
final String className;
31
32
static String getClassName(Class clazz) {
33
if (clazz == null) return null;
34
if (clazz.isArray())
35
return getClassName(clazz.getComponentType()) + "[]";
36
final String fullname = clazz.getName();
37
final int lastpoint = fullname.lastIndexOf('.');
38
final int len = fullname.length();
39
if ((lastpoint < 0) || (lastpoint >= len))
40
return fullname;
41
else return fullname.substring(lastpoint+1,len);
42
}
43
44
static String getLoggerName(Class clazz) {
45
if (clazz == null) return "sun.management.test";
46
Package p = clazz.getPackage();
47
if (p == null) return "sun.management.test";
48
final String pname = p.getName();
49
if (pname == null) return "sun.management.test";
50
else return pname;
51
}
52
53
public TestLogger(Class clazz) {
54
this(getLoggerName(clazz),getClassName(clazz));
55
}
56
57
public TestLogger(Class clazz, String postfix) {
58
this(getLoggerName(clazz)+((postfix==null)?"":"."+postfix),
59
getClassName(clazz));
60
}
61
62
public TestLogger(String className) {
63
this("sun.management.test",className);
64
}
65
66
public TestLogger(String loggerName, String className) {
67
Logger l = null;
68
try {
69
l = Logger.getLogger(loggerName);
70
} catch (Exception x) {
71
// OK. Should not happen
72
}
73
logger = l;
74
this.className=className;
75
}
76
77
protected Logger getLogger() {
78
return logger;
79
}
80
81
public boolean isTraceOn() {
82
final Logger l = getLogger();
83
if (l==null) return false;
84
return l.isLoggable(Level.FINE);
85
}
86
87
public boolean isDebugOn() {
88
final Logger l = getLogger();
89
if (l==null) return false;
90
return l.isLoggable(Level.FINEST);
91
}
92
93
public void error(String func, String msg) {
94
final Logger l = getLogger();
95
if (l!=null) l.logp(Level.SEVERE,className,
96
func,msg);
97
}
98
99
public void trace(String func, String msg) {
100
final Logger l = getLogger();
101
if (l!=null) l.logp(Level.FINE,className,
102
func,msg);
103
}
104
105
public void trace(String func, Throwable t) {
106
final Logger l = getLogger();
107
if (l!=null) l.logp(Level.FINE,className,
108
func,t.toString(),t);
109
}
110
111
public void trace(String func, String msg, Throwable t) {
112
final Logger l = getLogger();
113
if (l!=null) l.logp(Level.FINE,className,
114
func,msg,t);
115
}
116
117
public void debug(String func, String msg) {
118
final Logger l = getLogger();
119
if (l!=null) l.logp(Level.FINEST,className,
120
func,msg);
121
}
122
123
public void debug(String func, Throwable t) {
124
final Logger l = getLogger();
125
if (l!=null) l.logp(Level.FINEST,className,
126
func,t.toString(),t);
127
}
128
129
public void debug(String func, String msg, Throwable t) {
130
final Logger l = getLogger();
131
if (l!=null) l.logp(Level.FINEST,className,
132
func,msg,t);
133
}
134
}
135
136