1 *java.util.logging.LogManager* *LogManager* There is a single global LogManager
3 public class LogManager
4 extends |java.lang.Object|
6 |java.util.logging.LogManager_Description|
7 |java.util.logging.LogManager_Fields|
8 |java.util.logging.LogManager_Constructors|
9 |java.util.logging.LogManager_Methods|
11 ================================================================================
13 *java.util.logging.LogManager_Fields*
14 |java.lang.String_java.util.logging.LogManager.LOGGING_MXBEAN_NAME|
16 *java.util.logging.LogManager_Constructors*
17 |java.util.logging.LogManager()|Protected constructor.
19 *java.util.logging.LogManager_Methods*
20 |java.util.logging.LogManager.addLogger(Logger)|Add a named logger.
21 |java.util.logging.LogManager.addPropertyChangeListener(PropertyChangeListener)|
22 |java.util.logging.LogManager.checkAccess()|Check that the current context is t
23 |java.util.logging.LogManager.getLogger(String)|Method to find a named logger.
24 |java.util.logging.LogManager.getLoggerNames()|Get an enumeration of known logg
25 |java.util.logging.LogManager.getLoggingMXBean()|Returns LoggingMXBean for mana
26 |java.util.logging.LogManager.getLogManager()|Return the global LogManager obje
27 |java.util.logging.LogManager.getProperty(String)|Get the value of a logging pr
28 |java.util.logging.LogManager.readConfiguration()|Reinitialize the logging prop
29 |java.util.logging.LogManager.readConfiguration(InputStream)|Reinitialize the l
30 |java.util.logging.LogManager.removePropertyChangeListener(PropertyChangeListener)|
31 |java.util.logging.LogManager.reset()|Reset the logging configuration.
33 *java.util.logging.LogManager_Description*
35 There is a single global LogManager object that is used to maintain a set of
36 shared state about Loggers and log services.
38 This LogManager object:
40 Manages a hierarchical namespace of Logger objects. All named Loggers are
41 stored in this namespace. Manages a set of logging control properties. These
42 are simple key-value pairs that can be used by Handlers and other logging
43 objects to configure themselves.
45 The global LogManager object can be retrieved using LogManager.getLogManager().
46 The LogManager object is created during class initialization and cannot
47 subsequently be changed.
49 At startup the LogManager class is located using the java.util.logging.manager
52 By default, the LogManager reads its initial configuration from a properties
53 file "lib/logging.properties" in the JRE directory. If you edit that property
54 file you can change the default logging configuration for all uses of that JRE.
56 In addition, the LogManager uses two optional system properties that allow more
57 control over reading the initial configuration:
59 "java.util.logging.config.class" "java.util.logging.config.file"
61 These two properties may be set via the Preferences API, or as command line
62 property definitions to the "java" command, or as system property definitions
63 passed to JNI_CreateJavaVM.
65 If the "java.util.logging.config.class" property is set, then the property
66 value is treated as a class name. The given class will be loaded, an object
67 will be instantiated, and that object's constructor is responsible for reading
68 in the initial configuration. (That object may use other system properties to
69 control its configuration.) The alternate configuration class can use
70 readConfiguration(InputStream) to define properties in the LogManager.
72 If "java.util.logging.config.class" property is not set, then the
73 "java.util.logging.config.file" system property can be used to specify a
74 properties file (in java.util.Properties format). The initial logging
75 configuration will be read from this file.
77 If neither of these properties is defined then, as described above, the
78 LogManager will read its initial configuration from a properties file
79 "lib/logging.properties" in the JRE directory.
81 The properties for loggers and Handlers will have names starting with the
82 dot-separated name for the handler or logger.
84 The global logging properties may include:
86 A property "handlers". This defines a whitespace or comma separated list of
87 class names for handler classes to load and register as handlers on the root
88 Logger (the Logger named ""). Each class name must be for a Handler class which
89 has a default constructor. Note that these Handlers may be created lazily, when
92 A property "<logger>.handlers". This defines a whitespace or comma separated
93 list of class names for handlers classes to load and register as handlers to
94 the specified logger. Each class name must be for a Handler class which has a
95 default constructor. Note that these Handlers may be created lazily, when they
98 A property "<logger>.useParentHandlers". This defines a boolean value. By
99 default every logger calls its parent in addition to handling the logging
100 message itself, this often result in messages being handled by the root logger
101 as well. When setting this property to false a Handler needs to be configured
102 for this logger otherwise no logging messages are delivered.
104 A property "config". This property is intended to allow arbitrary configuration
105 code to be run. The property defines a whitespace or comma separated list of
106 class names. A new instance will be created for each named class. The default
107 constructor of each class may execute arbitrary code to update the logging
108 configuration, such as setting logger levels, adding handlers, adding filters,
111 Note that all classes loaded during LogManager configuration are first searched
112 on the system class path before any user class path. That includes the
113 LogManager class, any config classes, and any handler classes.
115 Loggers are organized into a naming hierarchy based on their dot separated
116 names. Thus "a.b.c" is a child of "a.b", but "a.b1" and a.b2" are peers.
118 All properties whose names end with ".level" are assumed to define log levels
119 for Loggers. Thus "foo.level" defines a log level for the logger called "foo"
120 and (recursively) for any of its children in the naming hierarchy. Log Levels
121 are applied in the order they are defined in the properties file. Thus level
122 settings for child nodes in the tree should come after settings for their
123 parents. The property name ".level" can be used to set the level for the root
126 All methods on the LogManager object are multi-thread safe.
130 *java.lang.String_java.util.logging.LogManager.LOGGING_MXBEAN_NAME*
132 String representation of the (|javax.management.ObjectName|) for
133 (|java.util.logging.LoggingMXBean|) .
137 *java.util.logging.LogManager()*
139 protected LogManager()
141 Protected constructor. This is protected so that container applications (such
142 as J2EE containers) can subclass the object. It is non-public as it is intended
143 that there only be one LogManager object, whose value is retrieved by calling
144 Logmanager.getLogManager.
147 *java.util.logging.LogManager.addLogger(Logger)*
149 public synchronized boolean addLogger(java.util.logging.Logger logger)
151 Add a named logger. This does nothing and returns false if a logger with the
152 same name is already registered.
154 The Logger factory methods call this method to register each newly created
157 The application should retain its own reference to the Logger object to avoid
158 it being garbage collected. The LogManager may only retain a weak reference.
161 logger - the new logger.
163 Returns: true if the argument logger was registered successfully, false if a logger of
164 that name already exists.
166 *java.util.logging.LogManager.addPropertyChangeListener(PropertyChangeListener)*
168 public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
169 throws |java.lang.SecurityException|
171 Adds an event listener to be invoked when the logging properties are re-read.
172 Adding multiple instances of the same event Listener results in multiple
173 entries in the property event listener table.
178 *java.util.logging.LogManager.checkAccess()*
180 public void checkAccess()
181 throws |java.lang.SecurityException|
183 Check that the current context is trusted to modify the logging configuration.
184 This requires LoggingPermission("control").
186 If the check fails we throw a SecurityException, otherwise we return normally.
190 *java.util.logging.LogManager.getLogger(String)*
192 public synchronized |java.util.logging.Logger| getLogger(java.lang.String name)
194 Method to find a named logger.
196 Note that since untrusted code may create loggers with arbitrary names this
197 method should not be relied on to find Loggers for security sensitive logging.
200 name - name of the logger
202 Returns: matching logger or null if none is found
204 *java.util.logging.LogManager.getLoggerNames()*
206 public synchronized |java.util.Enumeration|<String> getLoggerNames()
208 Get an enumeration of known logger names.
210 Note: Loggers may be added dynamically as new classes are loaded. This method
211 only reports on the loggers that are currently registered.
215 Returns: enumeration of logger name strings
217 *java.util.logging.LogManager.getLoggingMXBean()*
219 public static synchronized |java.util.logging.LoggingMXBean| getLoggingMXBean()
221 Returns LoggingMXBean for managing loggers. The LoggingMXBean can also obtained
223 <tt>MBeanServer</tt>(|java.lang.management.ManagementFactory|) method.
227 Returns: a {@link LoggingMXBean} object.
229 *java.util.logging.LogManager.getLogManager()*
231 public static |java.util.logging.LogManager| getLogManager()
233 Return the global LogManager object.
237 *java.util.logging.LogManager.getProperty(String)*
239 public |java.lang.String| getProperty(java.lang.String name)
241 Get the value of a logging property. The method returns null if the property is
247 Returns: property value
249 *java.util.logging.LogManager.readConfiguration()*
251 public void readConfiguration()
252 throws |java.io.IOException|
253 |java.lang.SecurityException|
255 Reinitialize the logging properties and reread the logging configuration.
257 The same rules are used for locating the configuration properties as are used
258 at startup. So normally the logging properties will be re-read from the same
259 file that was used at startup.
261 Any log level definitions in the new configuration file will be applied using
262 Logger.setLevel(), if the target Logger exists.
264 A PropertyChangeEvent will be fired after the properties are read.
268 *java.util.logging.LogManager.readConfiguration(InputStream)*
270 public void readConfiguration(java.io.InputStream ins)
271 throws |java.io.IOException|
272 |java.lang.SecurityException|
274 Reinitialize the logging properties and reread the logging configuration from
275 the given stream, which should be in java.util.Properties format. A
276 PropertyChangeEvent will be fired after the properties are read.
278 Any log level definitions in the new configuration file will be applied using
279 Logger.setLevel(), if the target Logger exists.
282 ins - stream to read properties from
284 *java.util.logging.LogManager.removePropertyChangeListener(PropertyChangeListener)*
286 public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
287 throws |java.lang.SecurityException|
289 Removes an event listener for property change events. If the same listener
290 instance has been added to the listener table through multiple invocations of
291 addPropertyChangeListener, then an equivalent number of
292 removePropertyChangeListener invocations are required to remove all instances
293 of that listener from the listener table.
295 Returns silently if the given listener is not found.
298 l - event listener (can be null)
300 *java.util.logging.LogManager.reset()*
303 throws |java.lang.SecurityException|
305 Reset the logging configuration.
307 For all named loggers, the reset operation removes and closes all Handlers and
308 (except for the root logger) sets the level to null. The root logger's level is