Top Description Fields Constructors Methods
org.hsqldb.lib

public Class FrameworkLogger

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.lang.reflect.InvocationTargetException, .Method, java.util.HashMap, .HashSet, .Iterator, .Map, .Set, java.util.logging.ConsoleHandler, .Level, .LogManager, .Logger

A logging framework wrapper that supports java.util.logging and log4j.

Logger hierarchies are stored at the Class level. Log4j will be used if the Log4j system (not necessarily config files) are found in the runtime classpath. Otherwise, java.util.logging will be used.

This is pretty safe because for use cases where multiple hierarchies are desired, classloader hierarchies will effectively isolate multiple class-level Logger hierarchies.

Sad as it is, the java.util.logging facility lacks the most basic developer-side and configuration-side capabilities. Besides having a non-scalable discovery system, the designers didn't comprehend the need for a level between WARNING and SEVERE! Since we don't want to require log4j in Classpath, we have to live with these constraints.

As with all the popular logging frameworks, if you want to capture a stack trace, you must use the two-parameters logging methods. I.e., you must also pass a String, or only toString() from your throwable will be captured.

Usage example:

private static FrameworkLogger logger =
       FrameworkLogger.getLog(SqlTool.class);
...
  logger.finer("Doing something log-worthy");

The system level property hsqldb.reconfig_logging=false is required to avoid configuration of java.util.logging. Otherwise configuration takes place.

Author
Blaine Simpson (blaine dot simpson at admc dot com)
Since
1.9.0
Version
2.7.3

Field Summary

Modifier and TypeField and Description
private static boolean
private Logger
private static Map<K, V>
private static Method
private Object
private static Method
private static Map<K, V>
private static boolean

Constructor Summary

AccessConstructor and Description
private
FrameworkLogger(String
String
s
)

User may not use the constructor.

Method Summary

Modifier and TypeMethod and Description
public static synchronized void
clearLoggers(String
String
prefixToZap
)

Frees Logger(s), if any, with the specified category, or that begins with the specified prefix + dot.

public void
enduserlog(Level level, String message)

public void
error(String
Message to be logged
message
)

This is just a wrapper for FrameworkLogger.warning(), because java.util.logging lacks a method for this critical purpose.

public void
error(String
String
message
,
Throwable
Throwable whose stack trace will be logged.
t
)

Just like FrameworkLogger.error(String), but also logs a stack trace.

public void
finer(String
Message to be logged
message
)

public void
finer(String
String
message
,
Throwable
Throwable whose stack trace will be logged.
t
)

Just like FrameworkLogger.finer(String), but also logs a stack trace.

public void
finest(String
Message to be logged
message
)

public void
finest(String
String
message
,
Throwable
Throwable whose stack trace will be logged.
t
)

Just like FrameworkLogger.finest(String), but also logs a stack trace.

public static FrameworkLogger

Returns:

FrameworkLogger
getLog
(Class<T>
Class
c
)

User's entry-point into this logging system.

public static FrameworkLogger

Returns:

FrameworkLogger
getLog
(Class<T>
Class
c
,
String
String
contextId
)

This method just defers to the getLog(Class) method unless default (no local configuration) JDK logging is being used; In that case, this method assures that the returned logger has an associated FileHander using the supplied String identifier.

public static FrameworkLogger

Returns:

FrameworkLogger
getLog
(String
String
baseId
,
String
String
contextId
)

This method just defers to the getLog(String) method unless default (no local configuration) JDK logging is being used; In that case, this method assures that the returned logger has an associated FileHander using the supplied String identifier.

public static synchronized FrameworkLogger

Returns:

FrameworkLogger
getLog
(String
String
s
)

Alternative entry-point into this logging system, for cases where you want to share a single logger instance among multiple classes, or you want to use multiple logger instances from a single class.

public void
info(String
Message to be logged
message
)

public void
info(String
String
message
,
Throwable
Throwable whose stack trace will be logged.
t
)

Just like FrameworkLogger.info(String), but also logs a stack trace.

public void
log(Level
java.util.logging.Level level to filter and log at
level
,
String
Message to be logged
message
,
Throwable
Throwable whose stack trace will be logged.
t
)

Just like FrameworkLogger.log(Level, String), but also logs a stack trace.

public void
log(Level
java.util.logging.Level level to filter and log at
level
,
String
Message to be logged
message
)

private static synchronized void
public void
privlog(Level
Level
level
,
String
String
message
,
Throwable
Throwable
t
,
int
int
revertMethods
,
Class<T>
Class
skipClass
)

The "priv" prefix is historical.

pack-priv static void
reconfigure()

Reconfigure log4j if present.

public static synchronized String

Returns:

String
report
()

Utility method for integrators.

public void
severe(String
Message to be logged
message
)

public void
severe(String
String
message
,
Throwable
Throwable whose stack trace will be logged.
t
)

Just like FrameworkLogger.severe(String), but also logs a stack trace.

public void
warning(String
Message to be logged
message
)

public void
warning(String
String
message
,
Throwable
Throwable whose stack trace will be logged.
t
)

Just like FrameworkLogger.warning(String), but also logs a stack trace.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callerFqcnAvailableback to summary
private static boolean callerFqcnAvailable
jdkLoggerback to summary
private Logger jdkLogger
jdkToLog4jLevelsback to summary
private static Map<K, V> jdkToLog4jLevels
log4jGetLoggerback to summary
private static Method log4jGetLogger
log4jLoggerback to summary
private Object log4jLogger
log4jLogMethodback to summary
private static Method log4jLogMethod
loggerInstancesback to summary
private static Map<K, V> loggerInstances
noopModeback to summary
private static boolean noopMode

Constructor Detail

FrameworkLoggerback to summary
private FrameworkLogger(String s)

User may not use the constructor.

Parameters
s:String

String

Method Detail

clearLoggersback to summary
public static synchronized void clearLoggers(String prefixToZap)

Frees Logger(s), if any, with the specified category, or that begins with the specified prefix + dot.

Note that as of today, this depends on the underlying logging framework implementation to release the underlying Logger instances. JUL in Sun's JVM uses weak references, so that should be fine. Log4j as of today seems to use strong references (and no API hooks to free anything), so this method will probably have little benefit for Log4j.

Parameters
prefixToZap:String

String

enduserlogback to summary
public void enduserlog(Level level, String message)
errorback to summary
public void error(String message)

This is just a wrapper for FrameworkLogger.warning(), because java.util.logging lacks a method for this critical purpose.

Parameters
message:String

Message to be logged

See Also
warning(String)
errorback to summary
public void error(String message, Throwable t)

Just like FrameworkLogger.error(String), but also logs a stack trace.

Parameters
message:String

String

t:Throwable

Throwable whose stack trace will be logged.

See Also
error(String)
finerback to summary
public void finer(String message)
Parameters
message:String

Message to be logged

See Also
Logger#finer(String)
finerback to summary
public void finer(String message, Throwable t)

Just like FrameworkLogger.finer(String), but also logs a stack trace.

Parameters
message:String

String

t:Throwable

Throwable whose stack trace will be logged.

See Also
finer(String)
finestback to summary
public void finest(String message)
Parameters
message:String

Message to be logged

See Also
Logger#finest(String)
finestback to summary
public void finest(String message, Throwable t)

Just like FrameworkLogger.finest(String), but also logs a stack trace.

Parameters
message:String

String

t:Throwable

Throwable whose stack trace will be logged.

See Also
finest(String)
getLogback to summary
public static FrameworkLogger getLog(Class<T> c)

User's entry-point into this logging system.

You normally want to work with static (class-level) pointers to logger instances, for performance efficiency. See the class-level JavaDoc for a usage example.

Parameters
c:Class<T>

Class

Returns:FrameworkLogger

FrameworkLogger

getLogback to summary
public static FrameworkLogger getLog(Class<T> c, String contextId)

This method just defers to the getLog(Class) method unless default (no local configuration) JDK logging is being used; In that case, this method assures that the returned logger has an associated FileHander using the supplied String identifier.

Parameters
c:Class<T>

Class

contextId:String

String

Returns:FrameworkLogger

FrameworkLogger

getLogback to summary
public static FrameworkLogger getLog(String baseId, String contextId)

This method just defers to the getLog(String) method unless default (no local configuration) JDK logging is being used; In that case, this method assures that the returned logger has an associated FileHander using the supplied String identifier.

Parameters
baseId:String

String

contextId:String

String

Returns:FrameworkLogger

FrameworkLogger

getLogback to summary
public static synchronized FrameworkLogger getLog(String s)

Alternative entry-point into this logging system, for cases where you want to share a single logger instance among multiple classes, or you want to use multiple logger instances from a single class.

Parameters
s:String

String

Returns:FrameworkLogger

FrameworkLogger

See Also
getLog(Class)
infoback to summary
public void info(String message)
Parameters
message:String

Message to be logged

See Also
Logger#info(String)
infoback to summary
public void info(String message, Throwable t)

Just like FrameworkLogger.info(String), but also logs a stack trace.

Parameters
message:String

String

t:Throwable

Throwable whose stack trace will be logged.

See Also
info(String)
logback to summary
public void log(Level level, String message, Throwable t)

Just like FrameworkLogger.log(Level, String), but also logs a stack trace.

Parameters
level:Level

java.util.logging.Level level to filter and log at

message:String

Message to be logged

t:Throwable

Throwable whose stack trace will be logged.

See Also
log(Level, String), Logger#log(Level, String), Level
logback to summary
public void log(Level level, String message)
Parameters
level:Level

java.util.logging.Level level to filter and log at

message:String

Message to be logged

See Also
Logger#log(Level, String), Level
populateJdkToLog4jLevelsback to summary
private static synchronized void populateJdkToLog4jLevels(String classString) throws ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException
privlogback to summary
public void privlog(Level level, String message, Throwable t, int revertMethods, Class<T> skipClass)

The "priv" prefix is historical. This is for special usage when you need to modify the reported call stack. If you don't know that you want to do this, then you should not use this method.

Parameters
level:Level

Level

message:String

String

t:Throwable

Throwable

revertMethods:int

int

skipClass:Class<T>

Class

reconfigureback to summary
pack-priv static void reconfigure()

Reconfigure log4j if present. (TODO: Class-presence test is inadequate. Should check Log4j is actuall used). Reconfigure java.util.logging otherwise

reportback to summary
public static synchronized String report()

Utility method for integrators. Returns a string representation of the active Logger instance keys.

Not named similar to 'toString' to avoid ambiguity with instance method toString.

Returns:String

String

severeback to summary
public void severe(String message)
Parameters
message:String

Message to be logged

See Also
Logger#severe(String)
severeback to summary
public void severe(String message, Throwable t)

Just like FrameworkLogger.severe(String), but also logs a stack trace.

Parameters
message:String

String

t:Throwable

Throwable whose stack trace will be logged.

See Also
severe(String)
warningback to summary
public void warning(String message)
Parameters
message:String

Message to be logged

See Also
Logger#warning(String)
warningback to summary
public void warning(String message, Throwable t)

Just like FrameworkLogger.warning(String), but also logs a stack trace.

Parameters
message:String

String

t:Throwable

Throwable whose stack trace will be logged.

See Also
warning(String)