public class LogHelper
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
LogHelper.CleanFormatter
Simple formatter to emit a very clean, condensed output.
|
Modifier and Type | Field and Description |
---|---|
private static boolean |
append
Append mode for the file handler.
|
private static java.util.logging.Level |
console
Logging level for the console handler (
OFF to disable). |
private static int |
count
Number of log generations for the file handler.
|
private static java.util.Set<java.util.logging.Logger> |
definedLoggers
The set of loggers defined into the directory configuration file.
|
private static java.util.logging.Level |
file
Logging level for the file handler (
OFF to disable). |
private static java.util.logging.FileHandler |
fileHandler
Shared file handler
|
private static java.util.logging.Level |
global
Global logging level (all unconfigured handlers inherit this).
|
private static int |
limit
Maximum file size in megabytes for the file handler.
|
private static java.util.Map<java.lang.String,java.util.logging.Level> |
loggerLevels
List of logger names and the associated log levels.
|
private static java.lang.String |
pattern
Filename pattern for the file handler.
|
Constructor and Description |
---|
LogHelper() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
createThreadName(java.lang.String descr)
Get a simplified string which describes the current context.
|
static java.lang.String |
describeContext()
Get a string which uniquely describes the current context.
|
static java.lang.String |
generate(java.lang.String msg)
Generate a standard prefix for this string which includes identifiers
of the current session's context.
|
static java.lang.String |
generate(java.lang.String spec,
java.lang.Object obj)
Substitute the given parameter into the specification string and then
append the result to the standard prefix which includes identifiers
of the current session's context.
|
static java.lang.String |
generate(java.lang.String spec,
java.lang.Object[] parms)
Substitute the given parameters into the specification string and then
append the result to the standard prefix which includes identifiers
of the current session's context.
|
static java.lang.String |
generate(java.lang.String spec,
java.lang.Object o1,
java.lang.Object o2)
Substitute the given parameters into the specification string and then
append the result to the standard prefix which includes identifiers
of the current session's context.
|
static java.lang.String |
generate(java.lang.String spec,
java.lang.Object o1,
java.lang.Object o2,
java.lang.Object o3)
Substitute the given parameters into the specification string and then
append the result to the standard prefix which includes identifiers
of the current session's context.
|
static java.util.logging.Logger |
getLogger(java.lang.Class<?> clazz)
Retrieve a logging object from the
LogManager . |
static java.util.logging.Logger |
getLogger(java.lang.String name)
Retrieve a logging object from the
LogManager . |
static java.util.logging.Logger |
getSecureLogger(boolean server)
Retrieve an anonymous logger (one that has no name and is not
accessible via the namespace) from the
LogManager and
configure it with independent (and inaccessible) instances of the
handlers with which the named loggers are configured. |
static java.util.logging.FileHandler |
initialize(java.lang.Class<? extends java.util.logging.FileHandler> fhClass,
java.util.logging.Level global,
java.util.logging.Level console,
java.util.logging.Level file,
java.lang.String pattern,
int limit,
int count,
boolean append,
java.util.Map<java.lang.String,java.util.logging.Level> loglevels)
Initialize the logging infrastructure using the given configuration.
|
static void |
initialize(java.lang.String serverName)
Initialize the logging infrastructure using the configuration stored
in the directory.
|
static java.util.logging.FileHandler |
initialize(java.lang.String serverName,
java.lang.Class<? extends java.util.logging.FileHandler> fhClass)
Initialize the logging infrastructure using the configuration stored
in the directory.
|
private static void |
initLogger(java.util.logging.Logger log)
Initialize the given logger with independent instances of the
file and console handlers as configured by
readConfiguration() . |
private static java.util.logging.FileHandler |
initWorker(java.lang.Class<? extends java.util.logging.FileHandler> fhClass)
Perform the core initialization using the previously stored and/or
default configuration values.
|
private static void |
readConfiguration()
Override the default configuration in this class with one read from
the directory.
|
private static void |
readConsoleConfig(DirectoryService ds,
java.lang.String root)
Read the logging level for the console and if it exists and specifies
a valid level, override the default.
|
private static void |
readFileConfig(DirectoryService ds,
java.lang.String root)
Read the configuration values for the file handler and if they exist
and specify valid values, override the default.
|
private static void |
readGlobalLevel(DirectoryService ds,
java.lang.String root)
Read the global default logging level and if it exists and specifies
a valid level, override the default.
|
private static java.util.logging.Level |
readLevel(DirectoryService ds,
java.lang.String nodeId)
Read the given node as a string and convert the string name into a
Level object. |
private static void |
readLoggerLevels(DirectoryService ds,
java.lang.String root)
Read the log level for an arbitrary list of loggers (as specified by
their hierarchical names).
|
private static java.util.logging.Level global
private static java.util.logging.Level console
OFF
to disable).private static java.util.logging.Level file
OFF
to disable).private static java.lang.String pattern
private static int limit
private static int count
private static boolean append
private static volatile java.util.Map<java.lang.String,java.util.logging.Level> loggerLevels
private static volatile java.util.logging.FileHandler fileHandler
private static java.util.Set<java.util.logging.Logger> definedLoggers
public static java.util.logging.FileHandler initialize(java.lang.Class<? extends java.util.logging.FileHandler> fhClass, java.util.logging.Level global, java.util.logging.Level console, java.util.logging.Level file, java.lang.String pattern, int limit, int count, boolean append, java.util.Map<java.lang.String,java.util.logging.Level> loglevels)
fhClass
- Class of a custom file handler instance to use for all loggers.
If this parameter is null
, a default handler will
be created. The class must be public and have a public
constructor of the signature:
{ClassName}(String pattern, int limit, int count, boolean append, Level logLevel, Formatter formatter)
global
- Global logging level (all unconfigured handlers inherit this).
null
to use the default.console
- Logging level for the console handler (OFF
to
disable). null
to use the default.file
- Logging level for the file handler (OFF
to
disable). null
to use the default.pattern
- Filename pattern for the file handler. null
to use
the default.limit
- Maximum file size in megabytes for the file handler. Use any
non-positive number to force the default value.count
- Number of log generations for the file handler. Use any
non-positive number to force the default value.append
- Append mode for the file handler.loglevels
- List of logger names and the associated log levels.fhClass
or null
if this
is not the first time initialize has been called.public static void initialize(java.lang.String serverName)
serverName
- The name of this server.public static java.util.logging.FileHandler initialize(java.lang.String serverName, java.lang.Class<? extends java.util.logging.FileHandler> fhClass)
serverName
- The name of this server.fhClass
- Class of a custom file handler instance to use for all loggers.
If this parameter is null
, a default handler will
be created. The class must be public and have a public
constructor of the signature:
{ClassName}(String pattern, int limit, int count, boolean append, Level logLevel, Formatter formatter)
fhClass
or null
if this
is not the first time initialize has been called.public static java.util.logging.Logger getLogger(java.lang.Class<?> clazz)
LogManager
.
The logger retrieved is scoped to the package name of the specified
class; thus, classes in the same package which use this method to
retrieve loggers will be sharing the same Log
instance.clazz
- Class object whose package name is used to scope the Logger.
If null
then an anonymous logger (one that has no
name and is not accessible via the namespace) will be
returned.public static java.util.logging.Logger getLogger(java.lang.String name)
LogManager
.
The logger retrieved is scoped to the arbitrary name specified. This
may be a classname, a package name or any arbitrary string. Any name
based on a package or class will naturally fit into the hierarchical
namespace for all loggers.name
- Name used to scope the Logger. If null
then an
anonymous logger (one that has no name and is not accessible
via the namespace) will be returned.public static java.util.logging.Logger getSecureLogger(boolean server)
LogManager
and
configure it with independent (and inaccessible) instances of the
handlers with which the named loggers are configured.
When called from the applet client, logging to the console causes the Java Security Manager to throw an Acess Denied exception. To prevent this, the client automatically initializes with the console handler turned off.
server
- true
if called from the server environment,
meaning the console handler will be set to OFF for the clientpublic static java.lang.String generate(java.lang.String msg)
msg
- The text to append to the session context ids.public static java.lang.String generate(java.lang.String spec, java.lang.Object[] parms)
spec
- The String.format
specification string.parms
- The substitution parameters.public static java.lang.String generate(java.lang.String spec, java.lang.Object obj)
spec
- The sprintf specification string.obj
- The single substitution parameter.public static java.lang.String generate(java.lang.String spec, java.lang.Object o1, java.lang.Object o2)
spec
- The sprintf specification string.o1
- The first substitution parameter.o2
- The second substitution parameter.public static java.lang.String generate(java.lang.String spec, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)
spec
- The sprintf specification string.o1
- The first substitution parameter.o2
- The second substitution parameter.o3
- The third substitution parameter.public static java.lang.String createThreadName(java.lang.String descr)
descr
- Description of the thread's purpose.public static java.lang.String describeContext()
private static java.util.logging.FileHandler initWorker(java.lang.Class<? extends java.util.logging.FileHandler> fhClass)
fhClass
- Class of a custom file handler instance to use for all loggers.
If this parameter is null
, a default handler will
be created. The class must be public and have a public
constructor of the signature:
{ClassName}(String pattern, int limit, int count, boolean append, Level logLevel, Formatter formatter)
fhClass
.private static void initLogger(java.util.logging.Logger log)
readConfiguration()
.log
- The logger to configure.private static void readConfiguration()
Root Paths ------------------------------------------- /server/<server_id>/logging /server/default/logging
If found, the local data members are set from the directory.
The following is read (where root is one of the root paths specified above):
Path Type Purpose ------------------------------------------- --------- ---------------- root + /level string global log level root + /handlers/console/level string console handler log level root + /handlers/file/level string file handler log level root + /handlers/file/pattern string file handler filename pattern root + /handlers/file/limit integer file handler log file size limit in kilobytes root + /handlers/file/count integer file handler number of log file generations root + /handlers/file/append boolean file handler should append to current log file root + /loggers/<logger_name>/level string log levels for any arbitrary logger name (in the hierarchical namespace)
Logging levels are specified as string names for as defined in the
java.util.logging.Level
class. They are (from least
inclusive to most inclusive):
OFF SEVERE WARNING INFO CONFIG FINE FINER FINEST ALL
Use OFF to disable any logger or handler. The handler configurations are global (all loggers output to these handlers).
private static void readGlobalLevel(DirectoryService ds, java.lang.String root)
The following is read:
Path Type ------------------------------------------- ------------------- root + /level string
ds
- A bound instance of the directory service.root
- The path to the root of the logging configuration.private static void readConsoleConfig(DirectoryService ds, java.lang.String root)
The following is read:
Path Type ------------------------------------------- ------------------- root + /handlers/console/level string
ds
- A bound instance of the directory service.root
- The path to the root of the logging configuration.private static void readFileConfig(DirectoryService ds, java.lang.String root)
The following is read:
Path Type ------------------------------------------- ------------------- root + /handlers/file/level string root + /handlers/file/pattern string root + /handlers/file/limit integer root + /handlers/file/count integer root + /handlers/file/append boolean
ds
- A bound instance of the directory service.root
- The path to the root of the logging configuration.private static void readLoggerLevels(DirectoryService ds, java.lang.String root)
The following is read (may be 0 or more of these entries, each name must be unique):
Path Type ------------------------------------------- ------------------- root + /loggers/<logger_name>/level string
ds
- A bound instance of the directory service.root
- The path to the root of the logging configuration.private static java.util.logging.Level readLevel(DirectoryService ds, java.lang.String nodeId)
Level
object.ds
- A bound instance of the directory service.nodeId
- The node to read.null
on any failure.