Package com.metsci.glimpse.util.logging
Class LoggerUtils
- java.lang.Object
-
- com.metsci.glimpse.util.logging.LoggerUtils
-
public class LoggerUtils extends Object
- Author:
- moskowitz
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLoggerUtils.LoggingOutputStreamAn OutputStream that writes contents to a Logger upon each call to flush() Original URL: https://blogs.oracle.com/nickstephen/entry/java_redirecting_system_out_and Author gives permission for free use in blog comments section.static classLoggerUtils.StdOutErrLevelClass defining 2 new Logging levels, one for STDOUT, one for STDERR, used when multiplexing STDOUT and STDERR into the same rolling log file via the Java Logging APIs.
From: http://blogs.sun.com/nickstephen/entry/java_redirecting_system_out_and
-
Constructor Summary
Constructors Constructor Description LoggerUtils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddTerseFileLogger(Level level, String filename)In cases where a logging.properties file is too cumbersome, sets terse formatter for file handler.voiddumpAncestry(Logger logger)Prints own and parents' log levels to standard out (for debugging).static LevelgetLevelRecursive(Logger logger)Traverses parents to find effective log level.static LoggergetLogger(Class<?> clazz)Convenience wrapper aroundLogger.getLogger(String).static booleaninitLogging(URL... urls)This method tries to configure logging by loading a configuration from each of the specified URLs, in order, until an attempt succeeds.static voidlog(Logger logger, Level level, String format, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlog(Logger logger, Level level, String format, Throwable thrown, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogConfig(Logger logger, String format, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogConfig(Logger logger, String format, Throwable thrown, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogFine(Logger logger, String format, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogFine(Logger logger, String format, Throwable thrown, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogFiner(Logger logger, String format, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogFiner(Logger logger, String format, Throwable thrown, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogFinest(Logger logger, String format, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogFinest(Logger logger, String format, Throwable thrown, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogInfo(Logger logger, String format, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogInfo(Logger logger, String format, Throwable thrown, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogSevere(Logger logger, String format, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogSevere(Logger logger, String format, Throwable thrown, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogWarning(Logger logger, String format, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidlogWarning(Logger logger, String format, Throwable thrown, Object... args)Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.static voidsendStderrToLog()static voidsendStdoutToLog()static voidsetConsoleLogger(Formatter formatter, Level level)static voidsetLoggerLevel(Level level)static voidsetTerseConsoleLogger(Level level)In cases where a logging.properties file is too cumbersome, sets terse formatter for console handler.
-
-
-
Field Detail
-
FORCE
public static final Level FORCE
Log statements with this level are always loggable -- even for loggers set to OFF.
-
-
Method Detail
-
getLogger
public static Logger getLogger(Class<?> clazz)
Convenience wrapper aroundLogger.getLogger(String). Uses the fully qualified classname of the specified class as the logger name.
-
getLevelRecursive
public static Level getLevelRecursive(Logger logger)
Traverses parents to find effective log level.
-
dumpAncestry
public void dumpAncestry(Logger logger)
Prints own and parents' log levels to standard out (for debugging).
-
initLogging
public static boolean initLogging(URL... urls)
This method tries to configure logging by loading a configuration from each of the specified URLs, in order, until an attempt succeeds. After the first successful attempt, the method returns true. If there are no successful attempts, the method returns false.Basic examples, using
IoUtils.file(String)andIoUtils#resource(Class, String):public static void main( String[] args ) { // Example 1: Use classpath resource "com/company/package/logging.properties" initLogging( Main.class.getResource( "logging.properties" ) ); ... // Example 2: Use a file, or fall back to classpath resource if file is not available initLogging( file( "logging.properties" ), resource( Main.class, "logging.properties" ) ); ... }
-
setTerseConsoleLogger
public static void setTerseConsoleLogger(Level level)
In cases where a logging.properties file is too cumbersome, sets terse formatter for console handler.- Parameters:
level- maximum logging level; set on root logger
-
addTerseFileLogger
public static final void addTerseFileLogger(Level level, String filename) throws SecurityException, IOException
In cases where a logging.properties file is too cumbersome, sets terse formatter for file handler.- Parameters:
level- maximum logging level; set on root logger- Throws:
IOExceptionSecurityException
-
setLoggerLevel
public static final void setLoggerLevel(Level level)
-
sendStdoutToLog
public static void sendStdoutToLog()
-
sendStderrToLog
public static void sendStderrToLog()
-
log
public static void log(Logger logger, Level level, String format, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logFinest
public static void logFinest(Logger logger, String format, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logFiner
public static void logFiner(Logger logger, String format, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logFine
public static void logFine(Logger logger, String format, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logConfig
public static void logConfig(Logger logger, String format, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logInfo
public static void logInfo(Logger logger, String format, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logWarning
public static void logWarning(Logger logger, String format, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logSevere
public static void logSevere(Logger logger, String format, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
log
public static void log(Logger logger, Level level, String format, Throwable thrown, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logFinest
public static void logFinest(Logger logger, String format, Throwable thrown, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logFiner
public static void logFiner(Logger logger, String format, Throwable thrown, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logFine
public static void logFine(Logger logger, String format, Throwable thrown, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logConfig
public static void logConfig(Logger logger, String format, Throwable thrown, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logInfo
public static void logInfo(Logger logger, String format, Throwable thrown, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
logWarning
public static void logWarning(Logger logger, String format, Throwable thrown, Object... args)
Wraps call to Java logger with varargs and performance optimization: no argument formatting if unneeded.
-
-