jaroslav@1258
|
1 |
/*
|
jaroslav@1258
|
2 |
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
|
jaroslav@1258
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@1258
|
4 |
*
|
jaroslav@1258
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@1258
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@1258
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@1258
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@1258
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@1258
|
10 |
*
|
jaroslav@1258
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@1258
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@1258
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@1258
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@1258
|
15 |
* accompanied this code).
|
jaroslav@1258
|
16 |
*
|
jaroslav@1258
|
17 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@1258
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@1258
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@1258
|
20 |
*
|
jaroslav@1258
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@1258
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@1258
|
23 |
* questions.
|
jaroslav@1258
|
24 |
*/
|
jaroslav@1258
|
25 |
|
jaroslav@1258
|
26 |
|
jaroslav@1258
|
27 |
package java.util.logging;
|
jaroslav@1258
|
28 |
|
jaroslav@1260
|
29 |
import java.util.HashMap;
|
jaroslav@1260
|
30 |
import java.util.Map;
|
jaroslav@1260
|
31 |
import org.apidesign.bck2brwsr.core.JavaScriptBody;
|
jaroslav@1258
|
32 |
|
jaroslav@1258
|
33 |
/**
|
jaroslav@1258
|
34 |
* A Logger object is used to log messages for a specific
|
jaroslav@1258
|
35 |
* system or application component. Loggers are normally named,
|
jaroslav@1258
|
36 |
* using a hierarchical dot-separated namespace. Logger names
|
jaroslav@1258
|
37 |
* can be arbitrary strings, but they should normally be based on
|
jaroslav@1258
|
38 |
* the package name or class name of the logged component, such
|
jaroslav@1258
|
39 |
* as java.net or javax.swing. In addition it is possible to create
|
jaroslav@1258
|
40 |
* "anonymous" Loggers that are not stored in the Logger namespace.
|
jaroslav@1258
|
41 |
* <p>
|
jaroslav@1258
|
42 |
* Logger objects may be obtained by calls on one of the getLogger
|
jaroslav@1258
|
43 |
* factory methods. These will either create a new Logger or
|
jaroslav@1258
|
44 |
* return a suitable existing Logger. It is important to note that
|
jaroslav@1258
|
45 |
* the Logger returned by one of the {@code getLogger} factory methods
|
jaroslav@1258
|
46 |
* may be garbage collected at any time if a strong reference to the
|
jaroslav@1258
|
47 |
* Logger is not kept.
|
jaroslav@1258
|
48 |
* <p>
|
jaroslav@1258
|
49 |
* Logging messages will be forwarded to registered Handler
|
jaroslav@1258
|
50 |
* objects, which can forward the messages to a variety of
|
jaroslav@1258
|
51 |
* destinations, including consoles, files, OS logs, etc.
|
jaroslav@1258
|
52 |
* <p>
|
jaroslav@1258
|
53 |
* Each Logger keeps track of a "parent" Logger, which is its
|
jaroslav@1258
|
54 |
* nearest existing ancestor in the Logger namespace.
|
jaroslav@1258
|
55 |
* <p>
|
jaroslav@1258
|
56 |
* Each Logger has a "Level" associated with it. This reflects
|
jaroslav@1258
|
57 |
* a minimum Level that this logger cares about. If a Logger's
|
jaroslav@1258
|
58 |
* level is set to <tt>null</tt>, then its effective level is inherited
|
jaroslav@1258
|
59 |
* from its parent, which may in turn obtain it recursively from its
|
jaroslav@1258
|
60 |
* parent, and so on up the tree.
|
jaroslav@1258
|
61 |
* <p>
|
jaroslav@1258
|
62 |
* The log level can be configured based on the properties from the
|
jaroslav@1258
|
63 |
* logging configuration file, as described in the description
|
jaroslav@1258
|
64 |
* of the LogManager class. However it may also be dynamically changed
|
jaroslav@1258
|
65 |
* by calls on the Logger.setLevel method. If a logger's level is
|
jaroslav@1258
|
66 |
* changed the change may also affect child loggers, since any child
|
jaroslav@1258
|
67 |
* logger that has <tt>null</tt> as its level will inherit its
|
jaroslav@1258
|
68 |
* effective level from its parent.
|
jaroslav@1258
|
69 |
* <p>
|
jaroslav@1258
|
70 |
* On each logging call the Logger initially performs a cheap
|
jaroslav@1258
|
71 |
* check of the request level (e.g., SEVERE or FINE) against the
|
jaroslav@1258
|
72 |
* effective log level of the logger. If the request level is
|
jaroslav@1258
|
73 |
* lower than the log level, the logging call returns immediately.
|
jaroslav@1258
|
74 |
* <p>
|
jaroslav@1258
|
75 |
* After passing this initial (cheap) test, the Logger will allocate
|
jaroslav@1258
|
76 |
* a LogRecord to describe the logging message. It will then call a
|
jaroslav@1258
|
77 |
* Filter (if present) to do a more detailed check on whether the
|
jaroslav@1258
|
78 |
* record should be published. If that passes it will then publish
|
jaroslav@1258
|
79 |
* the LogRecord to its output Handlers. By default, loggers also
|
jaroslav@1258
|
80 |
* publish to their parent's Handlers, recursively up the tree.
|
jaroslav@1258
|
81 |
* <p>
|
jaroslav@1258
|
82 |
* Each Logger may have a ResourceBundle name associated with it.
|
jaroslav@1258
|
83 |
* The named bundle will be used for localizing logging messages.
|
jaroslav@1258
|
84 |
* If a Logger does not have its own ResourceBundle name, then
|
jaroslav@1258
|
85 |
* it will inherit the ResourceBundle name from its parent,
|
jaroslav@1258
|
86 |
* recursively up the tree.
|
jaroslav@1258
|
87 |
* <p>
|
jaroslav@1258
|
88 |
* Most of the logger output methods take a "msg" argument. This
|
jaroslav@1258
|
89 |
* msg argument may be either a raw value or a localization key.
|
jaroslav@1258
|
90 |
* During formatting, if the logger has (or inherits) a localization
|
jaroslav@1258
|
91 |
* ResourceBundle and if the ResourceBundle has a mapping for the msg
|
jaroslav@1258
|
92 |
* string, then the msg string is replaced by the localized value.
|
jaroslav@1258
|
93 |
* Otherwise the original msg string is used. Typically, formatters use
|
jaroslav@1258
|
94 |
* java.text.MessageFormat style formatting to format parameters, so
|
jaroslav@1258
|
95 |
* for example a format string "{0} {1}" would format two parameters
|
jaroslav@1258
|
96 |
* as strings.
|
jaroslav@1258
|
97 |
* <p>
|
jaroslav@1258
|
98 |
* When mapping ResourceBundle names to ResourceBundles, the Logger
|
jaroslav@1258
|
99 |
* will first try to use the Thread's ContextClassLoader. If that
|
jaroslav@1258
|
100 |
* is null it will try the SystemClassLoader instead. As a temporary
|
jaroslav@1258
|
101 |
* transition feature in the initial implementation, if the Logger is
|
jaroslav@1258
|
102 |
* unable to locate a ResourceBundle from the ContextClassLoader or
|
jaroslav@1258
|
103 |
* SystemClassLoader the Logger will also search up the class stack
|
jaroslav@1258
|
104 |
* and use successive calling ClassLoaders to try to locate a ResourceBundle.
|
jaroslav@1258
|
105 |
* (This call stack search is to allow containers to transition to
|
jaroslav@1258
|
106 |
* using ContextClassLoaders and is likely to be removed in future
|
jaroslav@1258
|
107 |
* versions.)
|
jaroslav@1258
|
108 |
* <p>
|
jaroslav@1258
|
109 |
* Formatting (including localization) is the responsibility of
|
jaroslav@1258
|
110 |
* the output Handler, which will typically call a Formatter.
|
jaroslav@1258
|
111 |
* <p>
|
jaroslav@1258
|
112 |
* Note that formatting need not occur synchronously. It may be delayed
|
jaroslav@1258
|
113 |
* until a LogRecord is actually written to an external sink.
|
jaroslav@1258
|
114 |
* <p>
|
jaroslav@1258
|
115 |
* The logging methods are grouped in five main categories:
|
jaroslav@1258
|
116 |
* <ul>
|
jaroslav@1258
|
117 |
* <li><p>
|
jaroslav@1258
|
118 |
* There are a set of "log" methods that take a log level, a message
|
jaroslav@1258
|
119 |
* string, and optionally some parameters to the message string.
|
jaroslav@1258
|
120 |
* <li><p>
|
jaroslav@1258
|
121 |
* There are a set of "logp" methods (for "log precise") that are
|
jaroslav@1258
|
122 |
* like the "log" methods, but also take an explicit source class name
|
jaroslav@1258
|
123 |
* and method name.
|
jaroslav@1258
|
124 |
* <li><p>
|
jaroslav@1258
|
125 |
* There are a set of "logrb" method (for "log with resource bundle")
|
jaroslav@1258
|
126 |
* that are like the "logp" method, but also take an explicit resource
|
jaroslav@1258
|
127 |
* bundle name for use in localizing the log message.
|
jaroslav@1258
|
128 |
* <li><p>
|
jaroslav@1258
|
129 |
* There are convenience methods for tracing method entries (the
|
jaroslav@1258
|
130 |
* "entering" methods), method returns (the "exiting" methods) and
|
jaroslav@1258
|
131 |
* throwing exceptions (the "throwing" methods).
|
jaroslav@1258
|
132 |
* <li><p>
|
jaroslav@1258
|
133 |
* Finally, there are a set of convenience methods for use in the
|
jaroslav@1258
|
134 |
* very simplest cases, when a developer simply wants to log a
|
jaroslav@1258
|
135 |
* simple string at a given log level. These methods are named
|
jaroslav@1258
|
136 |
* after the standard Level names ("severe", "warning", "info", etc.)
|
jaroslav@1258
|
137 |
* and take a single argument, a message string.
|
jaroslav@1258
|
138 |
* </ul>
|
jaroslav@1258
|
139 |
* <p>
|
jaroslav@1258
|
140 |
* For the methods that do not take an explicit source name and
|
jaroslav@1258
|
141 |
* method name, the Logging framework will make a "best effort"
|
jaroslav@1258
|
142 |
* to determine which class and method called into the logging method.
|
jaroslav@1258
|
143 |
* However, it is important to realize that this automatically inferred
|
jaroslav@1258
|
144 |
* information may only be approximate (or may even be quite wrong!).
|
jaroslav@1258
|
145 |
* Virtual machines are allowed to do extensive optimizations when
|
jaroslav@1258
|
146 |
* JITing and may entirely remove stack frames, making it impossible
|
jaroslav@1258
|
147 |
* to reliably locate the calling class and method.
|
jaroslav@1258
|
148 |
* <P>
|
jaroslav@1258
|
149 |
* All methods on Logger are multi-thread safe.
|
jaroslav@1258
|
150 |
* <p>
|
jaroslav@1258
|
151 |
* <b>Subclassing Information:</b> Note that a LogManager class may
|
jaroslav@1258
|
152 |
* provide its own implementation of named Loggers for any point in
|
jaroslav@1258
|
153 |
* the namespace. Therefore, any subclasses of Logger (unless they
|
jaroslav@1258
|
154 |
* are implemented in conjunction with a new LogManager class) should
|
jaroslav@1258
|
155 |
* take care to obtain a Logger instance from the LogManager class and
|
jaroslav@1258
|
156 |
* should delegate operations such as "isLoggable" and "log(LogRecord)"
|
jaroslav@1258
|
157 |
* to that instance. Note that in order to intercept all logging
|
jaroslav@1258
|
158 |
* output, subclasses need only override the log(LogRecord) method.
|
jaroslav@1258
|
159 |
* All the other logging methods are implemented as calls on this
|
jaroslav@1258
|
160 |
* log(LogRecord) method.
|
jaroslav@1258
|
161 |
*
|
jaroslav@1258
|
162 |
* @since 1.4
|
jaroslav@1258
|
163 |
*/
|
jaroslav@1258
|
164 |
|
jaroslav@1258
|
165 |
|
jaroslav@1258
|
166 |
public class Logger {
|
jaroslav@1260
|
167 |
private static int offValue = Level.OFF.intValue();
|
jaroslav@1260
|
168 |
private static final Map<String,Logger> ALL = new HashMap<>();
|
jaroslav@1258
|
169 |
private String name;
|
jaroslav@1258
|
170 |
|
jaroslav@1258
|
171 |
private volatile int levelValue; // current effective level value
|
jaroslav@1260
|
172 |
private Level levelObject;
|
jaroslav@1260
|
173 |
|
jaroslav@1258
|
174 |
/**
|
jaroslav@1258
|
175 |
* GLOBAL_LOGGER_NAME is a name for the global logger.
|
jaroslav@1258
|
176 |
*
|
jaroslav@1258
|
177 |
* @since 1.6
|
jaroslav@1258
|
178 |
*/
|
jaroslav@1258
|
179 |
public static final String GLOBAL_LOGGER_NAME = "global";
|
jaroslav@1258
|
180 |
|
jaroslav@1258
|
181 |
/**
|
jaroslav@1258
|
182 |
* Return global logger object with the name Logger.GLOBAL_LOGGER_NAME.
|
jaroslav@1258
|
183 |
*
|
jaroslav@1258
|
184 |
* @return global logger object
|
jaroslav@1258
|
185 |
* @since 1.7
|
jaroslav@1258
|
186 |
*/
|
jaroslav@1258
|
187 |
public static final Logger getGlobal() {
|
jaroslav@1258
|
188 |
return global;
|
jaroslav@1258
|
189 |
}
|
jaroslav@1258
|
190 |
|
jaroslav@1258
|
191 |
/**
|
jaroslav@1258
|
192 |
* The "global" Logger object is provided as a convenience to developers
|
jaroslav@1258
|
193 |
* who are making casual use of the Logging package. Developers
|
jaroslav@1258
|
194 |
* who are making serious use of the logging package (for example
|
jaroslav@1258
|
195 |
* in products) should create and use their own Logger objects,
|
jaroslav@1258
|
196 |
* with appropriate names, so that logging can be controlled on a
|
jaroslav@1258
|
197 |
* suitable per-Logger granularity. Developers also need to keep a
|
jaroslav@1258
|
198 |
* strong reference to their Logger objects to prevent them from
|
jaroslav@1258
|
199 |
* being garbage collected.
|
jaroslav@1258
|
200 |
* <p>
|
jaroslav@1258
|
201 |
* @deprecated Initialization of this field is prone to deadlocks.
|
jaroslav@1258
|
202 |
* The field must be initialized by the Logger class initialization
|
jaroslav@1258
|
203 |
* which may cause deadlocks with the LogManager class initialization.
|
jaroslav@1258
|
204 |
* In such cases two class initialization wait for each other to complete.
|
jaroslav@1258
|
205 |
* The preferred way to get the global logger object is via the call
|
jaroslav@1258
|
206 |
* <code>Logger.getGlobal()</code>.
|
jaroslav@1258
|
207 |
* For compatibility with old JDK versions where the
|
jaroslav@1258
|
208 |
* <code>Logger.getGlobal()</code> is not available use the call
|
jaroslav@1258
|
209 |
* <code>Logger.getLogger(Logger.GLOBAL_LOGGER_NAME)</code>
|
jaroslav@1258
|
210 |
* or <code>Logger.getLogger("global")</code>.
|
jaroslav@1258
|
211 |
*/
|
jaroslav@1258
|
212 |
@Deprecated
|
jaroslav@1258
|
213 |
public static final Logger global = new Logger(GLOBAL_LOGGER_NAME);
|
jaroslav@1258
|
214 |
|
jaroslav@1258
|
215 |
/**
|
jaroslav@1258
|
216 |
* Protected method to construct a logger for a named subsystem.
|
jaroslav@1258
|
217 |
* <p>
|
jaroslav@1258
|
218 |
* The logger will be initially configured with a null Level
|
jaroslav@1258
|
219 |
* and with useParentHandlers set to true.
|
jaroslav@1258
|
220 |
*
|
jaroslav@1258
|
221 |
* @param name A name for the logger. This should
|
jaroslav@1258
|
222 |
* be a dot-separated name and should normally
|
jaroslav@1258
|
223 |
* be based on the package name or class name
|
jaroslav@1258
|
224 |
* of the subsystem, such as java.net
|
jaroslav@1258
|
225 |
* or javax.swing. It may be null for anonymous Loggers.
|
jaroslav@1258
|
226 |
* @param resourceBundleName name of ResourceBundle to be used for localizing
|
jaroslav@1258
|
227 |
* messages for this logger. May be null if none
|
jaroslav@1258
|
228 |
* of the messages require localization.
|
jaroslav@1258
|
229 |
* @throws MissingResourceException if the resourceBundleName is non-null and
|
jaroslav@1258
|
230 |
* no corresponding resource can be found.
|
jaroslav@1258
|
231 |
*/
|
jaroslav@1258
|
232 |
protected Logger(String name, String resourceBundleName) {
|
jaroslav@1258
|
233 |
this.name = name;
|
jaroslav@1258
|
234 |
levelValue = Level.INFO.intValue();
|
jaroslav@1258
|
235 |
}
|
jaroslav@1258
|
236 |
|
jaroslav@1258
|
237 |
// This constructor is used only to create the global Logger.
|
jaroslav@1258
|
238 |
// It is needed to break a cyclic dependence between the LogManager
|
jaroslav@1258
|
239 |
// and Logger static initializers causing deadlocks.
|
jaroslav@1258
|
240 |
private Logger(String name) {
|
jaroslav@1258
|
241 |
// The manager field is not initialized here.
|
jaroslav@1258
|
242 |
this.name = name;
|
jaroslav@1258
|
243 |
levelValue = Level.INFO.intValue();
|
jaroslav@1258
|
244 |
}
|
jaroslav@1258
|
245 |
|
jaroslav@1258
|
246 |
private void checkAccess() throws SecurityException {
|
jaroslav@1260
|
247 |
throw new SecurityException();
|
jaroslav@1258
|
248 |
}
|
jaroslav@1258
|
249 |
|
jaroslav@1258
|
250 |
/**
|
jaroslav@1258
|
251 |
* Find or create a logger for a named subsystem. If a logger has
|
jaroslav@1258
|
252 |
* already been created with the given name it is returned. Otherwise
|
jaroslav@1258
|
253 |
* a new logger is created.
|
jaroslav@1258
|
254 |
* <p>
|
jaroslav@1258
|
255 |
* If a new logger is created its log level will be configured
|
jaroslav@1258
|
256 |
* based on the LogManager configuration and it will configured
|
jaroslav@1258
|
257 |
* to also send logging output to its parent's Handlers. It will
|
jaroslav@1258
|
258 |
* be registered in the LogManager global namespace.
|
jaroslav@1258
|
259 |
* <p>
|
jaroslav@1258
|
260 |
* Note: The LogManager may only retain a weak reference to the newly
|
jaroslav@1258
|
261 |
* created Logger. It is important to understand that a previously
|
jaroslav@1258
|
262 |
* created Logger with the given name may be garbage collected at any
|
jaroslav@1258
|
263 |
* time if there is no strong reference to the Logger. In particular,
|
jaroslav@1258
|
264 |
* this means that two back-to-back calls like
|
jaroslav@1258
|
265 |
* {@code getLogger("MyLogger").log(...)} may use different Logger
|
jaroslav@1258
|
266 |
* objects named "MyLogger" if there is no strong reference to the
|
jaroslav@1258
|
267 |
* Logger named "MyLogger" elsewhere in the program.
|
jaroslav@1258
|
268 |
*
|
jaroslav@1258
|
269 |
* @param name A name for the logger. This should
|
jaroslav@1258
|
270 |
* be a dot-separated name and should normally
|
jaroslav@1258
|
271 |
* be based on the package name or class name
|
jaroslav@1258
|
272 |
* of the subsystem, such as java.net
|
jaroslav@1258
|
273 |
* or javax.swing
|
jaroslav@1258
|
274 |
* @return a suitable Logger
|
jaroslav@1258
|
275 |
* @throws NullPointerException if the name is null.
|
jaroslav@1258
|
276 |
*/
|
jaroslav@1258
|
277 |
|
jaroslav@1258
|
278 |
// Synchronization is not required here. All synchronization for
|
jaroslav@1258
|
279 |
// adding a new Logger object is handled by LogManager.addLogger().
|
jaroslav@1258
|
280 |
public static Logger getLogger(String name) {
|
jaroslav@1260
|
281 |
return getLogger(name, null);
|
jaroslav@1258
|
282 |
}
|
jaroslav@1258
|
283 |
|
jaroslav@1258
|
284 |
/**
|
jaroslav@1258
|
285 |
* Find or create a logger for a named subsystem. If a logger has
|
jaroslav@1258
|
286 |
* already been created with the given name it is returned. Otherwise
|
jaroslav@1258
|
287 |
* a new logger is created.
|
jaroslav@1258
|
288 |
* <p>
|
jaroslav@1258
|
289 |
* If a new logger is created its log level will be configured
|
jaroslav@1258
|
290 |
* based on the LogManager and it will configured to also send logging
|
jaroslav@1258
|
291 |
* output to its parent's Handlers. It will be registered in
|
jaroslav@1258
|
292 |
* the LogManager global namespace.
|
jaroslav@1258
|
293 |
* <p>
|
jaroslav@1258
|
294 |
* Note: The LogManager may only retain a weak reference to the newly
|
jaroslav@1258
|
295 |
* created Logger. It is important to understand that a previously
|
jaroslav@1258
|
296 |
* created Logger with the given name may be garbage collected at any
|
jaroslav@1258
|
297 |
* time if there is no strong reference to the Logger. In particular,
|
jaroslav@1258
|
298 |
* this means that two back-to-back calls like
|
jaroslav@1258
|
299 |
* {@code getLogger("MyLogger", ...).log(...)} may use different Logger
|
jaroslav@1258
|
300 |
* objects named "MyLogger" if there is no strong reference to the
|
jaroslav@1258
|
301 |
* Logger named "MyLogger" elsewhere in the program.
|
jaroslav@1258
|
302 |
* <p>
|
jaroslav@1258
|
303 |
* If the named Logger already exists and does not yet have a
|
jaroslav@1258
|
304 |
* localization resource bundle then the given resource bundle
|
jaroslav@1258
|
305 |
* name is used. If the named Logger already exists and has
|
jaroslav@1258
|
306 |
* a different resource bundle name then an IllegalArgumentException
|
jaroslav@1258
|
307 |
* is thrown.
|
jaroslav@1258
|
308 |
* <p>
|
jaroslav@1258
|
309 |
* @param name A name for the logger. This should
|
jaroslav@1258
|
310 |
* be a dot-separated name and should normally
|
jaroslav@1258
|
311 |
* be based on the package name or class name
|
jaroslav@1258
|
312 |
* of the subsystem, such as java.net
|
jaroslav@1258
|
313 |
* or javax.swing
|
jaroslav@1258
|
314 |
* @param resourceBundleName name of ResourceBundle to be used for localizing
|
jaroslav@1258
|
315 |
* messages for this logger. May be <CODE>null</CODE> if none of
|
jaroslav@1258
|
316 |
* the messages require localization.
|
jaroslav@1258
|
317 |
* @return a suitable Logger
|
jaroslav@1258
|
318 |
* @throws MissingResourceException if the resourceBundleName is non-null and
|
jaroslav@1258
|
319 |
* no corresponding resource can be found.
|
jaroslav@1258
|
320 |
* @throws IllegalArgumentException if the Logger already exists and uses
|
jaroslav@1258
|
321 |
* a different resource bundle name.
|
jaroslav@1258
|
322 |
* @throws NullPointerException if the name is null.
|
jaroslav@1258
|
323 |
*/
|
jaroslav@1258
|
324 |
|
jaroslav@1258
|
325 |
// Synchronization is not required here. All synchronization for
|
jaroslav@1258
|
326 |
// adding a new Logger object is handled by LogManager.addLogger().
|
jaroslav@1258
|
327 |
public static Logger getLogger(String name, String resourceBundleName) {
|
jaroslav@1260
|
328 |
Logger l = ALL.get(name);
|
jaroslav@1260
|
329 |
if (l == null) {
|
jaroslav@1260
|
330 |
l = new Logger(name, resourceBundleName);
|
jaroslav@1260
|
331 |
ALL.put(name, l);
|
jaroslav@1258
|
332 |
}
|
jaroslav@1260
|
333 |
return l;
|
jaroslav@1258
|
334 |
}
|
jaroslav@1258
|
335 |
|
jaroslav@1258
|
336 |
|
jaroslav@1258
|
337 |
/**
|
jaroslav@1258
|
338 |
* Create an anonymous Logger. The newly created Logger is not
|
jaroslav@1258
|
339 |
* registered in the LogManager namespace. There will be no
|
jaroslav@1258
|
340 |
* access checks on updates to the logger.
|
jaroslav@1258
|
341 |
* <p>
|
jaroslav@1258
|
342 |
* This factory method is primarily intended for use from applets.
|
jaroslav@1258
|
343 |
* Because the resulting Logger is anonymous it can be kept private
|
jaroslav@1258
|
344 |
* by the creating class. This removes the need for normal security
|
jaroslav@1258
|
345 |
* checks, which in turn allows untrusted applet code to update
|
jaroslav@1258
|
346 |
* the control state of the Logger. For example an applet can do
|
jaroslav@1258
|
347 |
* a setLevel or an addHandler on an anonymous Logger.
|
jaroslav@1258
|
348 |
* <p>
|
jaroslav@1258
|
349 |
* Even although the new logger is anonymous, it is configured
|
jaroslav@1258
|
350 |
* to have the root logger ("") as its parent. This means that
|
jaroslav@1258
|
351 |
* by default it inherits its effective level and handlers
|
jaroslav@1258
|
352 |
* from the root logger.
|
jaroslav@1258
|
353 |
* <p>
|
jaroslav@1258
|
354 |
*
|
jaroslav@1258
|
355 |
* @return a newly created private Logger
|
jaroslav@1258
|
356 |
*/
|
jaroslav@1258
|
357 |
public static Logger getAnonymousLogger() {
|
jaroslav@1258
|
358 |
return getAnonymousLogger(null);
|
jaroslav@1258
|
359 |
}
|
jaroslav@1258
|
360 |
|
jaroslav@1258
|
361 |
/**
|
jaroslav@1258
|
362 |
* Create an anonymous Logger. The newly created Logger is not
|
jaroslav@1258
|
363 |
* registered in the LogManager namespace. There will be no
|
jaroslav@1258
|
364 |
* access checks on updates to the logger.
|
jaroslav@1258
|
365 |
* <p>
|
jaroslav@1258
|
366 |
* This factory method is primarily intended for use from applets.
|
jaroslav@1258
|
367 |
* Because the resulting Logger is anonymous it can be kept private
|
jaroslav@1258
|
368 |
* by the creating class. This removes the need for normal security
|
jaroslav@1258
|
369 |
* checks, which in turn allows untrusted applet code to update
|
jaroslav@1258
|
370 |
* the control state of the Logger. For example an applet can do
|
jaroslav@1258
|
371 |
* a setLevel or an addHandler on an anonymous Logger.
|
jaroslav@1258
|
372 |
* <p>
|
jaroslav@1258
|
373 |
* Even although the new logger is anonymous, it is configured
|
jaroslav@1258
|
374 |
* to have the root logger ("") as its parent. This means that
|
jaroslav@1258
|
375 |
* by default it inherits its effective level and handlers
|
jaroslav@1258
|
376 |
* from the root logger.
|
jaroslav@1258
|
377 |
* <p>
|
jaroslav@1258
|
378 |
* @param resourceBundleName name of ResourceBundle to be used for localizing
|
jaroslav@1258
|
379 |
* messages for this logger.
|
jaroslav@1258
|
380 |
* May be null if none of the messages require localization.
|
jaroslav@1258
|
381 |
* @return a newly created private Logger
|
jaroslav@1258
|
382 |
* @throws MissingResourceException if the resourceBundleName is non-null and
|
jaroslav@1258
|
383 |
* no corresponding resource can be found.
|
jaroslav@1258
|
384 |
*/
|
jaroslav@1258
|
385 |
|
jaroslav@1258
|
386 |
// Synchronization is not required here. All synchronization for
|
jaroslav@1258
|
387 |
// adding a new anonymous Logger object is handled by doSetParent().
|
jaroslav@1258
|
388 |
public static Logger getAnonymousLogger(String resourceBundleName) {
|
jaroslav@1260
|
389 |
return new Logger(null, resourceBundleName);
|
jaroslav@1258
|
390 |
}
|
jaroslav@1258
|
391 |
|
jaroslav@1258
|
392 |
/**
|
jaroslav@1258
|
393 |
* Retrieve the localization resource bundle for this
|
jaroslav@1258
|
394 |
* logger for the current default locale. Note that if
|
jaroslav@1258
|
395 |
* the result is null, then the Logger will use a resource
|
jaroslav@1258
|
396 |
* bundle inherited from its parent.
|
jaroslav@1258
|
397 |
*
|
jaroslav@1258
|
398 |
* @return localization bundle (may be null)
|
jaroslav@1258
|
399 |
*/
|
jaroslav@1260
|
400 |
// public ResourceBundle getResourceBundle() {
|
jaroslav@1260
|
401 |
// return findResourceBundle(getResourceBundleName());
|
jaroslav@1260
|
402 |
// }
|
jaroslav@1258
|
403 |
|
jaroslav@1258
|
404 |
/**
|
jaroslav@1258
|
405 |
* Retrieve the localization resource bundle name for this
|
jaroslav@1258
|
406 |
* logger. Note that if the result is null, then the Logger
|
jaroslav@1258
|
407 |
* will use a resource bundle name inherited from its parent.
|
jaroslav@1258
|
408 |
*
|
jaroslav@1258
|
409 |
* @return localization bundle name (may be null)
|
jaroslav@1258
|
410 |
*/
|
jaroslav@1258
|
411 |
public String getResourceBundleName() {
|
jaroslav@1260
|
412 |
return null;
|
jaroslav@1258
|
413 |
}
|
jaroslav@1258
|
414 |
|
jaroslav@1258
|
415 |
/**
|
jaroslav@1258
|
416 |
* Set a filter to control output on this Logger.
|
jaroslav@1258
|
417 |
* <P>
|
jaroslav@1258
|
418 |
* After passing the initial "level" check, the Logger will
|
jaroslav@1258
|
419 |
* call this Filter to check if a log record should really
|
jaroslav@1258
|
420 |
* be published.
|
jaroslav@1258
|
421 |
*
|
jaroslav@1258
|
422 |
* @param newFilter a filter object (may be null)
|
jaroslav@1258
|
423 |
* @exception SecurityException if a security manager exists and if
|
jaroslav@1258
|
424 |
* the caller does not have LoggingPermission("control").
|
jaroslav@1258
|
425 |
*/
|
jaroslav@1260
|
426 |
// public void setFilter(Filter newFilter) throws SecurityException {
|
jaroslav@1260
|
427 |
// checkAccess();
|
jaroslav@1260
|
428 |
// }
|
jaroslav@1258
|
429 |
|
jaroslav@1258
|
430 |
/**
|
jaroslav@1258
|
431 |
* Get the current filter for this Logger.
|
jaroslav@1258
|
432 |
*
|
jaroslav@1258
|
433 |
* @return a filter object (may be null)
|
jaroslav@1258
|
434 |
*/
|
jaroslav@1260
|
435 |
// public Filter getFilter() {
|
jaroslav@1260
|
436 |
// return filter;
|
jaroslav@1260
|
437 |
// }
|
jaroslav@1258
|
438 |
|
jaroslav@1258
|
439 |
/**
|
jaroslav@1258
|
440 |
* Log a LogRecord.
|
jaroslav@1258
|
441 |
* <p>
|
jaroslav@1258
|
442 |
* All the other logging methods in this class call through
|
jaroslav@1258
|
443 |
* this method to actually perform any logging. Subclasses can
|
jaroslav@1258
|
444 |
* override this single method to capture all log activity.
|
jaroslav@1258
|
445 |
*
|
jaroslav@1258
|
446 |
* @param record the LogRecord to be published
|
jaroslav@1258
|
447 |
*/
|
jaroslav@1258
|
448 |
public void log(LogRecord record) {
|
jaroslav@1260
|
449 |
if (record.getLevel().intValue() < levelValue) {
|
jaroslav@1258
|
450 |
return;
|
jaroslav@1258
|
451 |
}
|
jaroslav@1277
|
452 |
|
jaroslav@1277
|
453 |
String method;
|
jaroslav@1277
|
454 |
switch (record.getLevel().toString()) {
|
jaroslav@1277
|
455 |
case "INFO": method = "info"; break;
|
jaroslav@1277
|
456 |
case "SEVERE": method = "error"; break;
|
jaroslav@1277
|
457 |
case "WARNING": method = "warn"; break;
|
jaroslav@1277
|
458 |
default: method = "log"; break;
|
jaroslav@1277
|
459 |
}
|
jaroslav@1355
|
460 |
|
jaroslav@1355
|
461 |
String msg = record.getMessage();
|
jaroslav@1355
|
462 |
final Object[] params = record.getParameters();
|
jaroslav@1355
|
463 |
if (params == null || params.length == 0) {
|
jaroslav@1355
|
464 |
} else {
|
jaroslav@1355
|
465 |
for (int i = 0; i < params.length; i++) {
|
jaroslav@1355
|
466 |
msg = msg.replace("{" + i + "}", params[i] == null ? "null" : params[i].toString());
|
jaroslav@1355
|
467 |
}
|
jaroslav@1355
|
468 |
}
|
jaroslav@1258
|
469 |
|
jaroslav@1260
|
470 |
consoleLog(
|
jaroslav@1277
|
471 |
method,
|
jaroslav@1355
|
472 |
record.getLoggerName(), msg);
|
jaroslav@1258
|
473 |
}
|
jaroslav@1260
|
474 |
|
jaroslav@1260
|
475 |
@JavaScriptBody(args = { "method", "logger", "msg" }, body =
|
jaroslav@1355
|
476 |
"if (console) console[method]('[' + logger + ']: ' + msg);"
|
jaroslav@1260
|
477 |
)
|
jaroslav@1260
|
478 |
private static native void consoleLog(
|
jaroslav@1260
|
479 |
String method, String logger, String msg
|
jaroslav@1260
|
480 |
);
|
jaroslav@1258
|
481 |
|
jaroslav@1258
|
482 |
// private support method for logging.
|
jaroslav@1258
|
483 |
// We fill in the logger name, resource bundle name, and
|
jaroslav@1258
|
484 |
// resource bundle and then call "void log(LogRecord)".
|
jaroslav@1258
|
485 |
private void doLog(LogRecord lr) {
|
jaroslav@1260
|
486 |
doLog(lr, lr.getResourceBundleName());
|
jaroslav@1260
|
487 |
}
|
jaroslav@1260
|
488 |
private void doLog(LogRecord lr, String bundleName) {
|
jaroslav@1258
|
489 |
lr.setLoggerName(name);
|
jaroslav@1258
|
490 |
log(lr);
|
jaroslav@1258
|
491 |
}
|
jaroslav@1258
|
492 |
|
jaroslav@1258
|
493 |
|
jaroslav@1258
|
494 |
//================================================================
|
jaroslav@1258
|
495 |
// Start of convenience methods WITHOUT className and methodName
|
jaroslav@1258
|
496 |
//================================================================
|
jaroslav@1258
|
497 |
|
jaroslav@1258
|
498 |
/**
|
jaroslav@1258
|
499 |
* Log a message, with no arguments.
|
jaroslav@1258
|
500 |
* <p>
|
jaroslav@1258
|
501 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
502 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
503 |
* registered output Handler objects.
|
jaroslav@1258
|
504 |
* <p>
|
jaroslav@1258
|
505 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
506 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
507 |
*/
|
jaroslav@1258
|
508 |
public void log(Level level, String msg) {
|
jaroslav@1258
|
509 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
510 |
return;
|
jaroslav@1258
|
511 |
}
|
jaroslav@1258
|
512 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
513 |
doLog(lr);
|
jaroslav@1258
|
514 |
}
|
jaroslav@1258
|
515 |
|
jaroslav@1258
|
516 |
/**
|
jaroslav@1258
|
517 |
* Log a message, with one object parameter.
|
jaroslav@1258
|
518 |
* <p>
|
jaroslav@1258
|
519 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
520 |
* level then a corresponding LogRecord is created and forwarded
|
jaroslav@1258
|
521 |
* to all the registered output Handler objects.
|
jaroslav@1258
|
522 |
* <p>
|
jaroslav@1258
|
523 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
524 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
525 |
* @param param1 parameter to the message
|
jaroslav@1258
|
526 |
*/
|
jaroslav@1258
|
527 |
public void log(Level level, String msg, Object param1) {
|
jaroslav@1258
|
528 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
529 |
return;
|
jaroslav@1258
|
530 |
}
|
jaroslav@1258
|
531 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
532 |
Object params[] = { param1 };
|
jaroslav@1258
|
533 |
lr.setParameters(params);
|
jaroslav@1258
|
534 |
doLog(lr);
|
jaroslav@1258
|
535 |
}
|
jaroslav@1258
|
536 |
|
jaroslav@1258
|
537 |
/**
|
jaroslav@1258
|
538 |
* Log a message, with an array of object arguments.
|
jaroslav@1258
|
539 |
* <p>
|
jaroslav@1258
|
540 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
541 |
* level then a corresponding LogRecord is created and forwarded
|
jaroslav@1258
|
542 |
* to all the registered output Handler objects.
|
jaroslav@1258
|
543 |
* <p>
|
jaroslav@1258
|
544 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
545 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
546 |
* @param params array of parameters to the message
|
jaroslav@1258
|
547 |
*/
|
jaroslav@1258
|
548 |
public void log(Level level, String msg, Object params[]) {
|
jaroslav@1258
|
549 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
550 |
return;
|
jaroslav@1258
|
551 |
}
|
jaroslav@1258
|
552 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
553 |
lr.setParameters(params);
|
jaroslav@1258
|
554 |
doLog(lr);
|
jaroslav@1258
|
555 |
}
|
jaroslav@1258
|
556 |
|
jaroslav@1258
|
557 |
/**
|
jaroslav@1258
|
558 |
* Log a message, with associated Throwable information.
|
jaroslav@1258
|
559 |
* <p>
|
jaroslav@1258
|
560 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
561 |
* level then the given arguments are stored in a LogRecord
|
jaroslav@1258
|
562 |
* which is forwarded to all registered output handlers.
|
jaroslav@1258
|
563 |
* <p>
|
jaroslav@1258
|
564 |
* Note that the thrown argument is stored in the LogRecord thrown
|
jaroslav@1258
|
565 |
* property, rather than the LogRecord parameters property. Thus is it
|
jaroslav@1258
|
566 |
* processed specially by output Formatters and is not treated
|
jaroslav@1258
|
567 |
* as a formatting parameter to the LogRecord message property.
|
jaroslav@1258
|
568 |
* <p>
|
jaroslav@1258
|
569 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
570 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
571 |
* @param thrown Throwable associated with log message.
|
jaroslav@1258
|
572 |
*/
|
jaroslav@1258
|
573 |
public void log(Level level, String msg, Throwable thrown) {
|
jaroslav@1258
|
574 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
575 |
return;
|
jaroslav@1258
|
576 |
}
|
jaroslav@1258
|
577 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
578 |
lr.setThrown(thrown);
|
jaroslav@1258
|
579 |
doLog(lr);
|
jaroslav@1258
|
580 |
}
|
jaroslav@1258
|
581 |
|
jaroslav@1258
|
582 |
//================================================================
|
jaroslav@1258
|
583 |
// Start of convenience methods WITH className and methodName
|
jaroslav@1258
|
584 |
//================================================================
|
jaroslav@1258
|
585 |
|
jaroslav@1258
|
586 |
/**
|
jaroslav@1258
|
587 |
* Log a message, specifying source class and method,
|
jaroslav@1258
|
588 |
* with no arguments.
|
jaroslav@1258
|
589 |
* <p>
|
jaroslav@1258
|
590 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
591 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
592 |
* registered output Handler objects.
|
jaroslav@1258
|
593 |
* <p>
|
jaroslav@1258
|
594 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
595 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
596 |
* @param sourceMethod name of method that issued the logging request
|
jaroslav@1258
|
597 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
598 |
*/
|
jaroslav@1258
|
599 |
public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
|
jaroslav@1258
|
600 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
601 |
return;
|
jaroslav@1258
|
602 |
}
|
jaroslav@1258
|
603 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
604 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
605 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
606 |
doLog(lr);
|
jaroslav@1258
|
607 |
}
|
jaroslav@1258
|
608 |
|
jaroslav@1258
|
609 |
/**
|
jaroslav@1258
|
610 |
* Log a message, specifying source class and method,
|
jaroslav@1258
|
611 |
* with a single object parameter to the log message.
|
jaroslav@1258
|
612 |
* <p>
|
jaroslav@1258
|
613 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
614 |
* level then a corresponding LogRecord is created and forwarded
|
jaroslav@1258
|
615 |
* to all the registered output Handler objects.
|
jaroslav@1258
|
616 |
* <p>
|
jaroslav@1258
|
617 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
618 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
619 |
* @param sourceMethod name of method that issued the logging request
|
jaroslav@1258
|
620 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
621 |
* @param param1 Parameter to the log message.
|
jaroslav@1258
|
622 |
*/
|
jaroslav@1258
|
623 |
public void logp(Level level, String sourceClass, String sourceMethod,
|
jaroslav@1258
|
624 |
String msg, Object param1) {
|
jaroslav@1258
|
625 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
626 |
return;
|
jaroslav@1258
|
627 |
}
|
jaroslav@1258
|
628 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
629 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
630 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
631 |
Object params[] = { param1 };
|
jaroslav@1258
|
632 |
lr.setParameters(params);
|
jaroslav@1258
|
633 |
doLog(lr);
|
jaroslav@1258
|
634 |
}
|
jaroslav@1258
|
635 |
|
jaroslav@1258
|
636 |
/**
|
jaroslav@1258
|
637 |
* Log a message, specifying source class and method,
|
jaroslav@1258
|
638 |
* with an array of object arguments.
|
jaroslav@1258
|
639 |
* <p>
|
jaroslav@1258
|
640 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
641 |
* level then a corresponding LogRecord is created and forwarded
|
jaroslav@1258
|
642 |
* to all the registered output Handler objects.
|
jaroslav@1258
|
643 |
* <p>
|
jaroslav@1258
|
644 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
645 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
646 |
* @param sourceMethod name of method that issued the logging request
|
jaroslav@1258
|
647 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
648 |
* @param params Array of parameters to the message
|
jaroslav@1258
|
649 |
*/
|
jaroslav@1258
|
650 |
public void logp(Level level, String sourceClass, String sourceMethod,
|
jaroslav@1258
|
651 |
String msg, Object params[]) {
|
jaroslav@1258
|
652 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
653 |
return;
|
jaroslav@1258
|
654 |
}
|
jaroslav@1258
|
655 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
656 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
657 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
658 |
lr.setParameters(params);
|
jaroslav@1258
|
659 |
doLog(lr);
|
jaroslav@1258
|
660 |
}
|
jaroslav@1258
|
661 |
|
jaroslav@1258
|
662 |
/**
|
jaroslav@1258
|
663 |
* Log a message, specifying source class and method,
|
jaroslav@1258
|
664 |
* with associated Throwable information.
|
jaroslav@1258
|
665 |
* <p>
|
jaroslav@1258
|
666 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
667 |
* level then the given arguments are stored in a LogRecord
|
jaroslav@1258
|
668 |
* which is forwarded to all registered output handlers.
|
jaroslav@1258
|
669 |
* <p>
|
jaroslav@1258
|
670 |
* Note that the thrown argument is stored in the LogRecord thrown
|
jaroslav@1258
|
671 |
* property, rather than the LogRecord parameters property. Thus is it
|
jaroslav@1258
|
672 |
* processed specially by output Formatters and is not treated
|
jaroslav@1258
|
673 |
* as a formatting parameter to the LogRecord message property.
|
jaroslav@1258
|
674 |
* <p>
|
jaroslav@1258
|
675 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
676 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
677 |
* @param sourceMethod name of method that issued the logging request
|
jaroslav@1258
|
678 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
679 |
* @param thrown Throwable associated with log message.
|
jaroslav@1258
|
680 |
*/
|
jaroslav@1258
|
681 |
public void logp(Level level, String sourceClass, String sourceMethod,
|
jaroslav@1258
|
682 |
String msg, Throwable thrown) {
|
jaroslav@1258
|
683 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
684 |
return;
|
jaroslav@1258
|
685 |
}
|
jaroslav@1258
|
686 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
687 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
688 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
689 |
lr.setThrown(thrown);
|
jaroslav@1258
|
690 |
doLog(lr);
|
jaroslav@1258
|
691 |
}
|
jaroslav@1258
|
692 |
|
jaroslav@1258
|
693 |
|
jaroslav@1258
|
694 |
//=========================================================================
|
jaroslav@1258
|
695 |
// Start of convenience methods WITH className, methodName and bundle name.
|
jaroslav@1258
|
696 |
//=========================================================================
|
jaroslav@1258
|
697 |
|
jaroslav@1258
|
698 |
|
jaroslav@1258
|
699 |
/**
|
jaroslav@1258
|
700 |
* Log a message, specifying source class, method, and resource bundle name
|
jaroslav@1258
|
701 |
* with no arguments.
|
jaroslav@1258
|
702 |
* <p>
|
jaroslav@1258
|
703 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
704 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
705 |
* registered output Handler objects.
|
jaroslav@1258
|
706 |
* <p>
|
jaroslav@1258
|
707 |
* The msg string is localized using the named resource bundle. If the
|
jaroslav@1258
|
708 |
* resource bundle name is null, or an empty String or invalid
|
jaroslav@1258
|
709 |
* then the msg string is not localized.
|
jaroslav@1258
|
710 |
* <p>
|
jaroslav@1258
|
711 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
712 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
713 |
* @param sourceMethod name of method that issued the logging request
|
jaroslav@1258
|
714 |
* @param bundleName name of resource bundle to localize msg,
|
jaroslav@1258
|
715 |
* can be null
|
jaroslav@1258
|
716 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
717 |
*/
|
jaroslav@1258
|
718 |
|
jaroslav@1258
|
719 |
public void logrb(Level level, String sourceClass, String sourceMethod,
|
jaroslav@1258
|
720 |
String bundleName, String msg) {
|
jaroslav@1258
|
721 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
722 |
return;
|
jaroslav@1258
|
723 |
}
|
jaroslav@1258
|
724 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
725 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
726 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
727 |
doLog(lr, bundleName);
|
jaroslav@1258
|
728 |
}
|
jaroslav@1258
|
729 |
|
jaroslav@1258
|
730 |
/**
|
jaroslav@1258
|
731 |
* Log a message, specifying source class, method, and resource bundle name,
|
jaroslav@1258
|
732 |
* with a single object parameter to the log message.
|
jaroslav@1258
|
733 |
* <p>
|
jaroslav@1258
|
734 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
735 |
* level then a corresponding LogRecord is created and forwarded
|
jaroslav@1258
|
736 |
* to all the registered output Handler objects.
|
jaroslav@1258
|
737 |
* <p>
|
jaroslav@1258
|
738 |
* The msg string is localized using the named resource bundle. If the
|
jaroslav@1258
|
739 |
* resource bundle name is null, or an empty String or invalid
|
jaroslav@1258
|
740 |
* then the msg string is not localized.
|
jaroslav@1258
|
741 |
* <p>
|
jaroslav@1258
|
742 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
743 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
744 |
* @param sourceMethod name of method that issued the logging request
|
jaroslav@1258
|
745 |
* @param bundleName name of resource bundle to localize msg,
|
jaroslav@1258
|
746 |
* can be null
|
jaroslav@1258
|
747 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
748 |
* @param param1 Parameter to the log message.
|
jaroslav@1258
|
749 |
*/
|
jaroslav@1258
|
750 |
public void logrb(Level level, String sourceClass, String sourceMethod,
|
jaroslav@1258
|
751 |
String bundleName, String msg, Object param1) {
|
jaroslav@1258
|
752 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
753 |
return;
|
jaroslav@1258
|
754 |
}
|
jaroslav@1258
|
755 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
756 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
757 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
758 |
Object params[] = { param1 };
|
jaroslav@1258
|
759 |
lr.setParameters(params);
|
jaroslav@1258
|
760 |
doLog(lr, bundleName);
|
jaroslav@1258
|
761 |
}
|
jaroslav@1258
|
762 |
|
jaroslav@1258
|
763 |
/**
|
jaroslav@1258
|
764 |
* Log a message, specifying source class, method, and resource bundle name,
|
jaroslav@1258
|
765 |
* with an array of object arguments.
|
jaroslav@1258
|
766 |
* <p>
|
jaroslav@1258
|
767 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
768 |
* level then a corresponding LogRecord is created and forwarded
|
jaroslav@1258
|
769 |
* to all the registered output Handler objects.
|
jaroslav@1258
|
770 |
* <p>
|
jaroslav@1258
|
771 |
* The msg string is localized using the named resource bundle. If the
|
jaroslav@1258
|
772 |
* resource bundle name is null, or an empty String or invalid
|
jaroslav@1258
|
773 |
* then the msg string is not localized.
|
jaroslav@1258
|
774 |
* <p>
|
jaroslav@1258
|
775 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
776 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
777 |
* @param sourceMethod name of method that issued the logging request
|
jaroslav@1258
|
778 |
* @param bundleName name of resource bundle to localize msg,
|
jaroslav@1258
|
779 |
* can be null.
|
jaroslav@1258
|
780 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
781 |
* @param params Array of parameters to the message
|
jaroslav@1258
|
782 |
*/
|
jaroslav@1258
|
783 |
public void logrb(Level level, String sourceClass, String sourceMethod,
|
jaroslav@1258
|
784 |
String bundleName, String msg, Object params[]) {
|
jaroslav@1258
|
785 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
786 |
return;
|
jaroslav@1258
|
787 |
}
|
jaroslav@1258
|
788 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
789 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
790 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
791 |
lr.setParameters(params);
|
jaroslav@1258
|
792 |
doLog(lr, bundleName);
|
jaroslav@1258
|
793 |
}
|
jaroslav@1258
|
794 |
|
jaroslav@1258
|
795 |
/**
|
jaroslav@1258
|
796 |
* Log a message, specifying source class, method, and resource bundle name,
|
jaroslav@1258
|
797 |
* with associated Throwable information.
|
jaroslav@1258
|
798 |
* <p>
|
jaroslav@1258
|
799 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
800 |
* level then the given arguments are stored in a LogRecord
|
jaroslav@1258
|
801 |
* which is forwarded to all registered output handlers.
|
jaroslav@1258
|
802 |
* <p>
|
jaroslav@1258
|
803 |
* The msg string is localized using the named resource bundle. If the
|
jaroslav@1258
|
804 |
* resource bundle name is null, or an empty String or invalid
|
jaroslav@1258
|
805 |
* then the msg string is not localized.
|
jaroslav@1258
|
806 |
* <p>
|
jaroslav@1258
|
807 |
* Note that the thrown argument is stored in the LogRecord thrown
|
jaroslav@1258
|
808 |
* property, rather than the LogRecord parameters property. Thus is it
|
jaroslav@1258
|
809 |
* processed specially by output Formatters and is not treated
|
jaroslav@1258
|
810 |
* as a formatting parameter to the LogRecord message property.
|
jaroslav@1258
|
811 |
* <p>
|
jaroslav@1258
|
812 |
* @param level One of the message level identifiers, e.g., SEVERE
|
jaroslav@1258
|
813 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
814 |
* @param sourceMethod name of method that issued the logging request
|
jaroslav@1258
|
815 |
* @param bundleName name of resource bundle to localize msg,
|
jaroslav@1258
|
816 |
* can be null
|
jaroslav@1258
|
817 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
818 |
* @param thrown Throwable associated with log message.
|
jaroslav@1258
|
819 |
*/
|
jaroslav@1258
|
820 |
public void logrb(Level level, String sourceClass, String sourceMethod,
|
jaroslav@1258
|
821 |
String bundleName, String msg, Throwable thrown) {
|
jaroslav@1258
|
822 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
823 |
return;
|
jaroslav@1258
|
824 |
}
|
jaroslav@1258
|
825 |
LogRecord lr = new LogRecord(level, msg);
|
jaroslav@1258
|
826 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
827 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
828 |
lr.setThrown(thrown);
|
jaroslav@1258
|
829 |
doLog(lr, bundleName);
|
jaroslav@1258
|
830 |
}
|
jaroslav@1258
|
831 |
|
jaroslav@1258
|
832 |
|
jaroslav@1258
|
833 |
//======================================================================
|
jaroslav@1258
|
834 |
// Start of convenience methods for logging method entries and returns.
|
jaroslav@1258
|
835 |
//======================================================================
|
jaroslav@1258
|
836 |
|
jaroslav@1258
|
837 |
/**
|
jaroslav@1258
|
838 |
* Log a method entry.
|
jaroslav@1258
|
839 |
* <p>
|
jaroslav@1258
|
840 |
* This is a convenience method that can be used to log entry
|
jaroslav@1258
|
841 |
* to a method. A LogRecord with message "ENTRY", log level
|
jaroslav@1258
|
842 |
* FINER, and the given sourceMethod and sourceClass is logged.
|
jaroslav@1258
|
843 |
* <p>
|
jaroslav@1258
|
844 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
845 |
* @param sourceMethod name of method that is being entered
|
jaroslav@1258
|
846 |
*/
|
jaroslav@1258
|
847 |
public void entering(String sourceClass, String sourceMethod) {
|
jaroslav@1258
|
848 |
if (Level.FINER.intValue() < levelValue) {
|
jaroslav@1258
|
849 |
return;
|
jaroslav@1258
|
850 |
}
|
jaroslav@1258
|
851 |
logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
|
jaroslav@1258
|
852 |
}
|
jaroslav@1258
|
853 |
|
jaroslav@1258
|
854 |
/**
|
jaroslav@1258
|
855 |
* Log a method entry, with one parameter.
|
jaroslav@1258
|
856 |
* <p>
|
jaroslav@1258
|
857 |
* This is a convenience method that can be used to log entry
|
jaroslav@1258
|
858 |
* to a method. A LogRecord with message "ENTRY {0}", log level
|
jaroslav@1258
|
859 |
* FINER, and the given sourceMethod, sourceClass, and parameter
|
jaroslav@1258
|
860 |
* is logged.
|
jaroslav@1258
|
861 |
* <p>
|
jaroslav@1258
|
862 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
863 |
* @param sourceMethod name of method that is being entered
|
jaroslav@1258
|
864 |
* @param param1 parameter to the method being entered
|
jaroslav@1258
|
865 |
*/
|
jaroslav@1258
|
866 |
public void entering(String sourceClass, String sourceMethod, Object param1) {
|
jaroslav@1258
|
867 |
if (Level.FINER.intValue() < levelValue) {
|
jaroslav@1258
|
868 |
return;
|
jaroslav@1258
|
869 |
}
|
jaroslav@1258
|
870 |
Object params[] = { param1 };
|
jaroslav@1258
|
871 |
logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
|
jaroslav@1258
|
872 |
}
|
jaroslav@1258
|
873 |
|
jaroslav@1258
|
874 |
/**
|
jaroslav@1258
|
875 |
* Log a method entry, with an array of parameters.
|
jaroslav@1258
|
876 |
* <p>
|
jaroslav@1258
|
877 |
* This is a convenience method that can be used to log entry
|
jaroslav@1258
|
878 |
* to a method. A LogRecord with message "ENTRY" (followed by a
|
jaroslav@1258
|
879 |
* format {N} indicator for each entry in the parameter array),
|
jaroslav@1258
|
880 |
* log level FINER, and the given sourceMethod, sourceClass, and
|
jaroslav@1258
|
881 |
* parameters is logged.
|
jaroslav@1258
|
882 |
* <p>
|
jaroslav@1258
|
883 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
884 |
* @param sourceMethod name of method that is being entered
|
jaroslav@1258
|
885 |
* @param params array of parameters to the method being entered
|
jaroslav@1258
|
886 |
*/
|
jaroslav@1258
|
887 |
public void entering(String sourceClass, String sourceMethod, Object params[]) {
|
jaroslav@1258
|
888 |
if (Level.FINER.intValue() < levelValue) {
|
jaroslav@1258
|
889 |
return;
|
jaroslav@1258
|
890 |
}
|
jaroslav@1258
|
891 |
String msg = "ENTRY";
|
jaroslav@1258
|
892 |
if (params == null ) {
|
jaroslav@1258
|
893 |
logp(Level.FINER, sourceClass, sourceMethod, msg);
|
jaroslav@1258
|
894 |
return;
|
jaroslav@1258
|
895 |
}
|
jaroslav@1258
|
896 |
for (int i = 0; i < params.length; i++) {
|
jaroslav@1258
|
897 |
msg = msg + " {" + i + "}";
|
jaroslav@1258
|
898 |
}
|
jaroslav@1258
|
899 |
logp(Level.FINER, sourceClass, sourceMethod, msg, params);
|
jaroslav@1258
|
900 |
}
|
jaroslav@1258
|
901 |
|
jaroslav@1258
|
902 |
/**
|
jaroslav@1258
|
903 |
* Log a method return.
|
jaroslav@1258
|
904 |
* <p>
|
jaroslav@1258
|
905 |
* This is a convenience method that can be used to log returning
|
jaroslav@1258
|
906 |
* from a method. A LogRecord with message "RETURN", log level
|
jaroslav@1258
|
907 |
* FINER, and the given sourceMethod and sourceClass is logged.
|
jaroslav@1258
|
908 |
* <p>
|
jaroslav@1258
|
909 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
910 |
* @param sourceMethod name of the method
|
jaroslav@1258
|
911 |
*/
|
jaroslav@1258
|
912 |
public void exiting(String sourceClass, String sourceMethod) {
|
jaroslav@1258
|
913 |
if (Level.FINER.intValue() < levelValue) {
|
jaroslav@1258
|
914 |
return;
|
jaroslav@1258
|
915 |
}
|
jaroslav@1258
|
916 |
logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
|
jaroslav@1258
|
917 |
}
|
jaroslav@1258
|
918 |
|
jaroslav@1258
|
919 |
|
jaroslav@1258
|
920 |
/**
|
jaroslav@1258
|
921 |
* Log a method return, with result object.
|
jaroslav@1258
|
922 |
* <p>
|
jaroslav@1258
|
923 |
* This is a convenience method that can be used to log returning
|
jaroslav@1258
|
924 |
* from a method. A LogRecord with message "RETURN {0}", log level
|
jaroslav@1258
|
925 |
* FINER, and the gives sourceMethod, sourceClass, and result
|
jaroslav@1258
|
926 |
* object is logged.
|
jaroslav@1258
|
927 |
* <p>
|
jaroslav@1258
|
928 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
929 |
* @param sourceMethod name of the method
|
jaroslav@1258
|
930 |
* @param result Object that is being returned
|
jaroslav@1258
|
931 |
*/
|
jaroslav@1258
|
932 |
public void exiting(String sourceClass, String sourceMethod, Object result) {
|
jaroslav@1258
|
933 |
if (Level.FINER.intValue() < levelValue) {
|
jaroslav@1258
|
934 |
return;
|
jaroslav@1258
|
935 |
}
|
jaroslav@1258
|
936 |
Object params[] = { result };
|
jaroslav@1258
|
937 |
logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", result);
|
jaroslav@1258
|
938 |
}
|
jaroslav@1258
|
939 |
|
jaroslav@1258
|
940 |
/**
|
jaroslav@1258
|
941 |
* Log throwing an exception.
|
jaroslav@1258
|
942 |
* <p>
|
jaroslav@1258
|
943 |
* This is a convenience method to log that a method is
|
jaroslav@1258
|
944 |
* terminating by throwing an exception. The logging is done
|
jaroslav@1258
|
945 |
* using the FINER level.
|
jaroslav@1258
|
946 |
* <p>
|
jaroslav@1258
|
947 |
* If the logger is currently enabled for the given message
|
jaroslav@1258
|
948 |
* level then the given arguments are stored in a LogRecord
|
jaroslav@1258
|
949 |
* which is forwarded to all registered output handlers. The
|
jaroslav@1258
|
950 |
* LogRecord's message is set to "THROW".
|
jaroslav@1258
|
951 |
* <p>
|
jaroslav@1258
|
952 |
* Note that the thrown argument is stored in the LogRecord thrown
|
jaroslav@1258
|
953 |
* property, rather than the LogRecord parameters property. Thus is it
|
jaroslav@1258
|
954 |
* processed specially by output Formatters and is not treated
|
jaroslav@1258
|
955 |
* as a formatting parameter to the LogRecord message property.
|
jaroslav@1258
|
956 |
* <p>
|
jaroslav@1258
|
957 |
* @param sourceClass name of class that issued the logging request
|
jaroslav@1258
|
958 |
* @param sourceMethod name of the method.
|
jaroslav@1258
|
959 |
* @param thrown The Throwable that is being thrown.
|
jaroslav@1258
|
960 |
*/
|
jaroslav@1258
|
961 |
public void throwing(String sourceClass, String sourceMethod, Throwable thrown) {
|
jaroslav@1258
|
962 |
if (Level.FINER.intValue() < levelValue || levelValue == offValue ) {
|
jaroslav@1258
|
963 |
return;
|
jaroslav@1258
|
964 |
}
|
jaroslav@1258
|
965 |
LogRecord lr = new LogRecord(Level.FINER, "THROW");
|
jaroslav@1258
|
966 |
lr.setSourceClassName(sourceClass);
|
jaroslav@1258
|
967 |
lr.setSourceMethodName(sourceMethod);
|
jaroslav@1258
|
968 |
lr.setThrown(thrown);
|
jaroslav@1258
|
969 |
doLog(lr);
|
jaroslav@1258
|
970 |
}
|
jaroslav@1258
|
971 |
|
jaroslav@1258
|
972 |
//=======================================================================
|
jaroslav@1258
|
973 |
// Start of simple convenience methods using level names as method names
|
jaroslav@1258
|
974 |
//=======================================================================
|
jaroslav@1258
|
975 |
|
jaroslav@1258
|
976 |
/**
|
jaroslav@1258
|
977 |
* Log a SEVERE message.
|
jaroslav@1258
|
978 |
* <p>
|
jaroslav@1258
|
979 |
* If the logger is currently enabled for the SEVERE message
|
jaroslav@1258
|
980 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
981 |
* registered output Handler objects.
|
jaroslav@1258
|
982 |
* <p>
|
jaroslav@1258
|
983 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
984 |
*/
|
jaroslav@1258
|
985 |
public void severe(String msg) {
|
jaroslav@1258
|
986 |
if (Level.SEVERE.intValue() < levelValue) {
|
jaroslav@1258
|
987 |
return;
|
jaroslav@1258
|
988 |
}
|
jaroslav@1258
|
989 |
log(Level.SEVERE, msg);
|
jaroslav@1258
|
990 |
}
|
jaroslav@1258
|
991 |
|
jaroslav@1258
|
992 |
/**
|
jaroslav@1258
|
993 |
* Log a WARNING message.
|
jaroslav@1258
|
994 |
* <p>
|
jaroslav@1258
|
995 |
* If the logger is currently enabled for the WARNING message
|
jaroslav@1258
|
996 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
997 |
* registered output Handler objects.
|
jaroslav@1258
|
998 |
* <p>
|
jaroslav@1258
|
999 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
1000 |
*/
|
jaroslav@1258
|
1001 |
public void warning(String msg) {
|
jaroslav@1258
|
1002 |
if (Level.WARNING.intValue() < levelValue) {
|
jaroslav@1258
|
1003 |
return;
|
jaroslav@1258
|
1004 |
}
|
jaroslav@1258
|
1005 |
log(Level.WARNING, msg);
|
jaroslav@1258
|
1006 |
}
|
jaroslav@1258
|
1007 |
|
jaroslav@1258
|
1008 |
/**
|
jaroslav@1258
|
1009 |
* Log an INFO message.
|
jaroslav@1258
|
1010 |
* <p>
|
jaroslav@1258
|
1011 |
* If the logger is currently enabled for the INFO message
|
jaroslav@1258
|
1012 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
1013 |
* registered output Handler objects.
|
jaroslav@1258
|
1014 |
* <p>
|
jaroslav@1258
|
1015 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
1016 |
*/
|
jaroslav@1258
|
1017 |
public void info(String msg) {
|
jaroslav@1258
|
1018 |
if (Level.INFO.intValue() < levelValue) {
|
jaroslav@1258
|
1019 |
return;
|
jaroslav@1258
|
1020 |
}
|
jaroslav@1258
|
1021 |
log(Level.INFO, msg);
|
jaroslav@1258
|
1022 |
}
|
jaroslav@1258
|
1023 |
|
jaroslav@1258
|
1024 |
/**
|
jaroslav@1258
|
1025 |
* Log a CONFIG message.
|
jaroslav@1258
|
1026 |
* <p>
|
jaroslav@1258
|
1027 |
* If the logger is currently enabled for the CONFIG message
|
jaroslav@1258
|
1028 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
1029 |
* registered output Handler objects.
|
jaroslav@1258
|
1030 |
* <p>
|
jaroslav@1258
|
1031 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
1032 |
*/
|
jaroslav@1258
|
1033 |
public void config(String msg) {
|
jaroslav@1258
|
1034 |
if (Level.CONFIG.intValue() < levelValue) {
|
jaroslav@1258
|
1035 |
return;
|
jaroslav@1258
|
1036 |
}
|
jaroslav@1258
|
1037 |
log(Level.CONFIG, msg);
|
jaroslav@1258
|
1038 |
}
|
jaroslav@1258
|
1039 |
|
jaroslav@1258
|
1040 |
/**
|
jaroslav@1258
|
1041 |
* Log a FINE message.
|
jaroslav@1258
|
1042 |
* <p>
|
jaroslav@1258
|
1043 |
* If the logger is currently enabled for the FINE message
|
jaroslav@1258
|
1044 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
1045 |
* registered output Handler objects.
|
jaroslav@1258
|
1046 |
* <p>
|
jaroslav@1258
|
1047 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
1048 |
*/
|
jaroslav@1258
|
1049 |
public void fine(String msg) {
|
jaroslav@1258
|
1050 |
if (Level.FINE.intValue() < levelValue) {
|
jaroslav@1258
|
1051 |
return;
|
jaroslav@1258
|
1052 |
}
|
jaroslav@1258
|
1053 |
log(Level.FINE, msg);
|
jaroslav@1258
|
1054 |
}
|
jaroslav@1258
|
1055 |
|
jaroslav@1258
|
1056 |
/**
|
jaroslav@1258
|
1057 |
* Log a FINER message.
|
jaroslav@1258
|
1058 |
* <p>
|
jaroslav@1258
|
1059 |
* If the logger is currently enabled for the FINER message
|
jaroslav@1258
|
1060 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
1061 |
* registered output Handler objects.
|
jaroslav@1258
|
1062 |
* <p>
|
jaroslav@1258
|
1063 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
1064 |
*/
|
jaroslav@1258
|
1065 |
public void finer(String msg) {
|
jaroslav@1258
|
1066 |
if (Level.FINER.intValue() < levelValue) {
|
jaroslav@1258
|
1067 |
return;
|
jaroslav@1258
|
1068 |
}
|
jaroslav@1258
|
1069 |
log(Level.FINER, msg);
|
jaroslav@1258
|
1070 |
}
|
jaroslav@1258
|
1071 |
|
jaroslav@1258
|
1072 |
/**
|
jaroslav@1258
|
1073 |
* Log a FINEST message.
|
jaroslav@1258
|
1074 |
* <p>
|
jaroslav@1258
|
1075 |
* If the logger is currently enabled for the FINEST message
|
jaroslav@1258
|
1076 |
* level then the given message is forwarded to all the
|
jaroslav@1258
|
1077 |
* registered output Handler objects.
|
jaroslav@1258
|
1078 |
* <p>
|
jaroslav@1258
|
1079 |
* @param msg The string message (or a key in the message catalog)
|
jaroslav@1258
|
1080 |
*/
|
jaroslav@1258
|
1081 |
public void finest(String msg) {
|
jaroslav@1258
|
1082 |
if (Level.FINEST.intValue() < levelValue) {
|
jaroslav@1258
|
1083 |
return;
|
jaroslav@1258
|
1084 |
}
|
jaroslav@1258
|
1085 |
log(Level.FINEST, msg);
|
jaroslav@1258
|
1086 |
}
|
jaroslav@1258
|
1087 |
|
jaroslav@1258
|
1088 |
//================================================================
|
jaroslav@1258
|
1089 |
// End of convenience methods
|
jaroslav@1258
|
1090 |
//================================================================
|
jaroslav@1258
|
1091 |
|
jaroslav@1258
|
1092 |
/**
|
jaroslav@1258
|
1093 |
* Set the log level specifying which message levels will be
|
jaroslav@1258
|
1094 |
* logged by this logger. Message levels lower than this
|
jaroslav@1258
|
1095 |
* value will be discarded. The level value Level.OFF
|
jaroslav@1258
|
1096 |
* can be used to turn off logging.
|
jaroslav@1258
|
1097 |
* <p>
|
jaroslav@1258
|
1098 |
* If the new level is null, it means that this node should
|
jaroslav@1258
|
1099 |
* inherit its level from its nearest ancestor with a specific
|
jaroslav@1258
|
1100 |
* (non-null) level value.
|
jaroslav@1258
|
1101 |
*
|
jaroslav@1258
|
1102 |
* @param newLevel the new value for the log level (may be null)
|
jaroslav@1258
|
1103 |
* @exception SecurityException if a security manager exists and if
|
jaroslav@1258
|
1104 |
* the caller does not have LoggingPermission("control").
|
jaroslav@1258
|
1105 |
*/
|
jaroslav@1258
|
1106 |
public void setLevel(Level newLevel) throws SecurityException {
|
jaroslav@1260
|
1107 |
levelValue = newLevel.intValue();
|
jaroslav@1260
|
1108 |
levelObject = newLevel;
|
jaroslav@1258
|
1109 |
}
|
jaroslav@1258
|
1110 |
|
jaroslav@1258
|
1111 |
/**
|
jaroslav@1258
|
1112 |
* Get the log Level that has been specified for this Logger.
|
jaroslav@1258
|
1113 |
* The result may be null, which means that this logger's
|
jaroslav@1258
|
1114 |
* effective level will be inherited from its parent.
|
jaroslav@1258
|
1115 |
*
|
jaroslav@1258
|
1116 |
* @return this Logger's level
|
jaroslav@1258
|
1117 |
*/
|
jaroslav@1258
|
1118 |
public Level getLevel() {
|
jaroslav@1258
|
1119 |
return levelObject;
|
jaroslav@1258
|
1120 |
}
|
jaroslav@1258
|
1121 |
|
jaroslav@1258
|
1122 |
/**
|
jaroslav@1258
|
1123 |
* Check if a message of the given level would actually be logged
|
jaroslav@1258
|
1124 |
* by this logger. This check is based on the Loggers effective level,
|
jaroslav@1258
|
1125 |
* which may be inherited from its parent.
|
jaroslav@1258
|
1126 |
*
|
jaroslav@1258
|
1127 |
* @param level a message logging level
|
jaroslav@1258
|
1128 |
* @return true if the given message level is currently being logged.
|
jaroslav@1258
|
1129 |
*/
|
jaroslav@1258
|
1130 |
public boolean isLoggable(Level level) {
|
jaroslav@1258
|
1131 |
if (level.intValue() < levelValue || levelValue == offValue) {
|
jaroslav@1258
|
1132 |
return false;
|
jaroslav@1258
|
1133 |
}
|
jaroslav@1258
|
1134 |
return true;
|
jaroslav@1258
|
1135 |
}
|
jaroslav@1258
|
1136 |
|
jaroslav@1258
|
1137 |
/**
|
jaroslav@1258
|
1138 |
* Get the name for this logger.
|
jaroslav@1258
|
1139 |
* @return logger name. Will be null for anonymous Loggers.
|
jaroslav@1258
|
1140 |
*/
|
jaroslav@1258
|
1141 |
public String getName() {
|
jaroslav@1258
|
1142 |
return name;
|
jaroslav@1258
|
1143 |
}
|
jaroslav@1258
|
1144 |
|
jaroslav@1258
|
1145 |
/**
|
jaroslav@1258
|
1146 |
* Add a log Handler to receive logging messages.
|
jaroslav@1258
|
1147 |
* <p>
|
jaroslav@1258
|
1148 |
* By default, Loggers also send their output to their parent logger.
|
jaroslav@1258
|
1149 |
* Typically the root Logger is configured with a set of Handlers
|
jaroslav@1258
|
1150 |
* that essentially act as default handlers for all loggers.
|
jaroslav@1258
|
1151 |
*
|
jaroslav@1258
|
1152 |
* @param handler a logging Handler
|
jaroslav@1258
|
1153 |
* @exception SecurityException if a security manager exists and if
|
jaroslav@1258
|
1154 |
* the caller does not have LoggingPermission("control").
|
jaroslav@1258
|
1155 |
*/
|
jaroslav@1260
|
1156 |
// public void addHandler(Handler handler) throws SecurityException {
|
jaroslav@1260
|
1157 |
// // Check for null handler
|
jaroslav@1260
|
1158 |
// handler.getClass();
|
jaroslav@1260
|
1159 |
// checkAccess();
|
jaroslav@1260
|
1160 |
// handlers.add(handler);
|
jaroslav@1260
|
1161 |
// }
|
jaroslav@1258
|
1162 |
|
jaroslav@1258
|
1163 |
/**
|
jaroslav@1258
|
1164 |
* Remove a log Handler.
|
jaroslav@1258
|
1165 |
* <P>
|
jaroslav@1258
|
1166 |
* Returns silently if the given Handler is not found or is null
|
jaroslav@1258
|
1167 |
*
|
jaroslav@1258
|
1168 |
* @param handler a logging Handler
|
jaroslav@1258
|
1169 |
* @exception SecurityException if a security manager exists and if
|
jaroslav@1258
|
1170 |
* the caller does not have LoggingPermission("control").
|
jaroslav@1258
|
1171 |
*/
|
jaroslav@1260
|
1172 |
// public void removeHandler(Handler handler) throws SecurityException {
|
jaroslav@1260
|
1173 |
// checkAccess();
|
jaroslav@1260
|
1174 |
// if (handler == null) {
|
jaroslav@1260
|
1175 |
// return;
|
jaroslav@1260
|
1176 |
// }
|
jaroslav@1260
|
1177 |
// handlers.remove(handler);
|
jaroslav@1260
|
1178 |
// }
|
jaroslav@1258
|
1179 |
|
jaroslav@1258
|
1180 |
/**
|
jaroslav@1258
|
1181 |
* Get the Handlers associated with this logger.
|
jaroslav@1258
|
1182 |
* <p>
|
jaroslav@1258
|
1183 |
* @return an array of all registered Handlers
|
jaroslav@1258
|
1184 |
*/
|
jaroslav@1260
|
1185 |
// public Handler[] getHandlers() {
|
jaroslav@1260
|
1186 |
// return handlers.toArray(emptyHandlers);
|
jaroslav@1260
|
1187 |
// }
|
jaroslav@1258
|
1188 |
|
jaroslav@1258
|
1189 |
/**
|
jaroslav@1258
|
1190 |
* Specify whether or not this logger should send its output
|
jaroslav@1258
|
1191 |
* to its parent Logger. This means that any LogRecords will
|
jaroslav@1258
|
1192 |
* also be written to the parent's Handlers, and potentially
|
jaroslav@1258
|
1193 |
* to its parent, recursively up the namespace.
|
jaroslav@1258
|
1194 |
*
|
jaroslav@1258
|
1195 |
* @param useParentHandlers true if output is to be sent to the
|
jaroslav@1258
|
1196 |
* logger's parent.
|
jaroslav@1258
|
1197 |
* @exception SecurityException if a security manager exists and if
|
jaroslav@1258
|
1198 |
* the caller does not have LoggingPermission("control").
|
jaroslav@1258
|
1199 |
*/
|
jaroslav@1258
|
1200 |
public void setUseParentHandlers(boolean useParentHandlers) {
|
jaroslav@1258
|
1201 |
checkAccess();
|
jaroslav@1258
|
1202 |
}
|
jaroslav@1258
|
1203 |
|
jaroslav@1258
|
1204 |
/**
|
jaroslav@1258
|
1205 |
* Discover whether or not this logger is sending its output
|
jaroslav@1258
|
1206 |
* to its parent logger.
|
jaroslav@1258
|
1207 |
*
|
jaroslav@1258
|
1208 |
* @return true if output is to be sent to the logger's parent
|
jaroslav@1258
|
1209 |
*/
|
jaroslav@1258
|
1210 |
public boolean getUseParentHandlers() {
|
jaroslav@1260
|
1211 |
return true;
|
jaroslav@1258
|
1212 |
}
|
jaroslav@1258
|
1213 |
|
jaroslav@1258
|
1214 |
/**
|
jaroslav@1258
|
1215 |
* Return the parent for this Logger.
|
jaroslav@1258
|
1216 |
* <p>
|
jaroslav@1258
|
1217 |
* This method returns the nearest extant parent in the namespace.
|
jaroslav@1258
|
1218 |
* Thus if a Logger is called "a.b.c.d", and a Logger called "a.b"
|
jaroslav@1258
|
1219 |
* has been created but no logger "a.b.c" exists, then a call of
|
jaroslav@1258
|
1220 |
* getParent on the Logger "a.b.c.d" will return the Logger "a.b".
|
jaroslav@1258
|
1221 |
* <p>
|
jaroslav@1258
|
1222 |
* The result will be null if it is called on the root Logger
|
jaroslav@1258
|
1223 |
* in the namespace.
|
jaroslav@1258
|
1224 |
*
|
jaroslav@1258
|
1225 |
* @return nearest existing parent Logger
|
jaroslav@1258
|
1226 |
*/
|
jaroslav@1258
|
1227 |
public Logger getParent() {
|
jaroslav@1258
|
1228 |
// Note: this used to be synchronized on treeLock. However, this only
|
jaroslav@1258
|
1229 |
// provided memory semantics, as there was no guarantee that the caller
|
jaroslav@1258
|
1230 |
// would synchronize on treeLock (in fact, there is no way for external
|
jaroslav@1258
|
1231 |
// callers to so synchronize). Therefore, we have made parent volatile
|
jaroslav@1258
|
1232 |
// instead.
|
jaroslav@1260
|
1233 |
String n = getName();
|
jaroslav@1260
|
1234 |
int at = n.length();
|
jaroslav@1260
|
1235 |
for (;;) {
|
jaroslav@1260
|
1236 |
int last = n.lastIndexOf('.', at - 1);
|
jaroslav@1260
|
1237 |
if (last == -1) {
|
jaroslav@1260
|
1238 |
return getGlobal();
|
jaroslav@1260
|
1239 |
}
|
jaroslav@1260
|
1240 |
Logger p = ALL.get(n.substring(0, last));
|
jaroslav@1260
|
1241 |
if (p != null) {
|
jaroslav@1260
|
1242 |
return p;
|
jaroslav@1260
|
1243 |
}
|
jaroslav@1260
|
1244 |
at = last;
|
jaroslav@1260
|
1245 |
}
|
jaroslav@1258
|
1246 |
}
|
jaroslav@1258
|
1247 |
|
jaroslav@1258
|
1248 |
/**
|
jaroslav@1258
|
1249 |
* Set the parent for this Logger. This method is used by
|
jaroslav@1258
|
1250 |
* the LogManager to update a Logger when the namespace changes.
|
jaroslav@1258
|
1251 |
* <p>
|
jaroslav@1258
|
1252 |
* It should not be called from application code.
|
jaroslav@1258
|
1253 |
* <p>
|
jaroslav@1258
|
1254 |
* @param parent the new parent logger
|
jaroslav@1258
|
1255 |
* @exception SecurityException if a security manager exists and if
|
jaroslav@1258
|
1256 |
* the caller does not have LoggingPermission("control").
|
jaroslav@1258
|
1257 |
*/
|
jaroslav@1258
|
1258 |
public void setParent(Logger parent) {
|
jaroslav@1258
|
1259 |
if (parent == null) {
|
jaroslav@1258
|
1260 |
throw new NullPointerException();
|
jaroslav@1258
|
1261 |
}
|
jaroslav@1260
|
1262 |
checkAccess();
|
jaroslav@1258
|
1263 |
}
|
jaroslav@1258
|
1264 |
|
jaroslav@1258
|
1265 |
}
|