com.fasterxml.uuid
Class Logger

java.lang.Object
  extended by com.fasterxml.uuid.Logger
Direct Known Subclasses:
JavaUtilLogger, Log4jLogger

public class Logger
extends Object

This is the simple logging interface used by JUG package. It is meant to provide a minimal but sufficient functionality for JUG to report problems (warnings, errors), in a way that it can be sufficiently customized (redirected, suppressed; even redefined), without forcing overhead of a real full-featured logging sub-system (like log4j or java.util.logging). By being customizable, it is still possible to connect JUG logging into real logging framework (log4j, java.util.logging) used by application or system that uses JUG.

To keep things as light-weight as possible, we won't bother defining separate interface or abstract class -- this class defines both API and the default implementation. It can thus be extended to override functionality to provide things like bridging to "real" logging systems. For simple configuration (suppress all, redirect to another stream) default implementation should be sufficient, however.

Note: package com.fasterxml.uuid.ext does contain simple wrappers to connect JUG logging to log4j and java.util.logging:

See Also:
Log4jLogger, JavaUtilLogger

Field Summary
protected  int _logLevel
          Threshold to use for outputting varius log statements.
protected  PrintStream _output1
          Output object to use, if defined; initialized to System.err.
protected  PrintWriter _output2
          Override output used to explicitly specify where to pass diagnostic output, instead of System.err.
static int LOG_ALL
           
static int LOG_ERROR_AND_ABOVE
           
static int LOG_INFO_AND_ABOVE
           
static int LOG_NOTHING
           
static int LOG_WARNING_AND_ABOVE
           
 
Constructor Summary
protected Logger()
           
 
Method Summary
protected  void doLogError(String msg)
           
protected  void doLogInfo(String msg)
           
protected  void doLogWarning(String msg)
           
protected  void doSetLogLevel(int ll)
           
protected  void doSetOutput(PrintStream str)
           
protected  void doSetOutput(Writer w)
           
protected  void doWrite(String msg)
           
protected  boolean isEnabled()
          Internal method used to quickly check if the Logger's output is suppressed or not.
static void logError(String msg)
           
static void logInfo(String msg)
           
static void logWarning(String msg)
           
static void setLogger(Logger inst)
          Method that can be used to completely re-define the logging functionality JUG uses.
static void setLogLevel(int level)
          Method to set the minimum level of messages that will get logged using currently specific logger instace.
static void setOutput(PrintStream str)
          Method that will re-direct output of the logger using the specified PrintStream.
static void setOutput(Writer w)
          Method that will re-direct output of the logger using the specified Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_ALL

public static final int LOG_ALL
See Also:
Constant Field Values

LOG_INFO_AND_ABOVE

public static final int LOG_INFO_AND_ABOVE
See Also:
Constant Field Values

LOG_WARNING_AND_ABOVE

public static final int LOG_WARNING_AND_ABOVE
See Also:
Constant Field Values

LOG_ERROR_AND_ABOVE

public static final int LOG_ERROR_AND_ABOVE
See Also:
Constant Field Values

LOG_NOTHING

public static final int LOG_NOTHING
See Also:
Constant Field Values

_logLevel

protected int _logLevel
Threshold to use for outputting varius log statements.

Default is to low only warnings and errors


_output1

protected PrintStream _output1
Output object to use, if defined; initialized to System.err.


_output2

protected PrintWriter _output2
Override output used to explicitly specify where to pass diagnostic output, instead of System.err. Used if _output1 is null;

Constructor Detail

Logger

protected Logger()
Method Detail

setLogger

public static void setLogger(Logger inst)
Method that can be used to completely re-define the logging functionality JUG uses. When called, JUG will start using the new instance; if instance passed is null, will basically suppress all logging.

Parameters:
inst - Logger instance to use for all logging JUG does; can be null, but if so, essentially disables all logging.

setLogLevel

public static void setLogLevel(int level)
Method to set the minimum level of messages that will get logged using currently specific logger instace. For example, if LOG_WARNING_AND_ABOVE is passed as the argument, warnings and errors will be logged, but informational (INFO) messages will not.

Note: exact functionality invoked depends on the logger instance: sub-classes of this class may need to do mapping to some other logging sub-system (log4j and JUL logging, for example, use their own severity levels that while generally reasonably easy to map, are nonetheless not one-to-one which the simple logger).


setOutput

public static void setOutput(PrintStream str)
Method that will re-direct output of the logger using the specified PrintStream. Null is allowed, and signifies that all the output should be suppressed.

Note: exact functionality invoked depends on the logger instance.


setOutput

public static void setOutput(Writer w)
Method that will re-direct output of the logger using the specified Writer. Null is allowed, and signifies that all the output should be suppressed.


logInfo

public static void logInfo(String msg)

logWarning

public static void logWarning(String msg)

logError

public static void logError(String msg)

doSetLogLevel

protected void doSetLogLevel(int ll)

doSetOutput

protected void doSetOutput(PrintStream str)

doSetOutput

protected void doSetOutput(Writer w)

doLogInfo

protected void doLogInfo(String msg)

doLogWarning

protected void doLogWarning(String msg)

doLogError

protected void doLogError(String msg)

doWrite

protected void doWrite(String msg)

isEnabled

protected boolean isEnabled()
Internal method used to quickly check if the Logger's output is suppressed or not.

Note: not synchronized since it's read-only method that's return value can not be used for reliable syncing.



Copyright © 2011 FasterXML.com. All Rights Reserved.