Class WriterLogger
- java.lang.Object
-
- WriterLogger
-
- All Implemented Interfaces:
Logger
public class WriterLogger extends java.lang.Object implements Logger
Provides an implementation of theLoggerinterface that sends output to the specifiedjava.io.Writer.Each log entry is formatted using the
BasicLogFormatter.format(String level, String message, String loggerName)method.Note that each logging level can be enabled independently in this implementation. All levels are enabled by default.
-
-
Constructor Summary
Constructors Constructor Description WriterLogger(java.io.Writer writer)Constructs a newWriterLoggerwith the specifiedWriterand the default name.WriterLogger(java.io.Writer writer, java.lang.String name)Constructs a newWriterLoggerwith the specifiedWriterand name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddebug(java.lang.String message)Logs a message at the DEBUG level.voiderror(java.lang.String message)Logs a message at the ERROR level.java.lang.StringgetName()Returns the name of this logger.java.io.WritergetWriter()Returns theWriterto which all output is sent.voidinfo(java.lang.String message)Logs a message at the INFO level.booleanisDebugEnabled()Indicates whether logging is enabled at the DEBUG level.booleanisErrorEnabled()Indicates whether logging is enabled at the ERROR level.booleanisInfoEnabled()Indicates whether logging is enabled at the INFO level.booleanisWarnEnabled()Indicates whether logging is enabled at the WARN level.protected voidlog(java.lang.String level, java.lang.String message)Logs the specified message at the specified level.voidsetDebugEnabled(boolean debugEnabled)Sets whether logging is enabled at the DEBUG level.voidsetErrorEnabled(boolean errorEnabled)Sets whether logging is enabled at the ERROR level.voidsetInfoEnabled(boolean infoEnabled)Sets whether logging is enabled at the INFO level.voidsetWarnEnabled(boolean warnEnabled)Sets whether logging is enabled at the WARN level.voidwarn(java.lang.String message)Logs a message at the WARN level.
-
-
-
Constructor Detail
-
WriterLogger
public WriterLogger(java.io.Writer writer)
Constructs a newWriterLoggerwith the specifiedWriterand the default name.The default logger name is "
net.htmlparser.jericho".- Parameters:
writer- theWriterto which all output is sent.
-
WriterLogger
public WriterLogger(java.io.Writer writer, java.lang.String name)Constructs a newWriterLoggerwith the specifiedWriterand name.The value of the
nameargument is only relevant if theBasicLogFormatter.OutputNamestatic property is set totrue, otherwise the name is not included in the output at all.- Parameters:
writer- theWriterto which all output is sent.name- the logger name, may benull.
-
-
Method Detail
-
getWriter
public java.io.Writer getWriter()
Returns theWriterto which all output is sent.- Returns:
- the
Writerto which all output is sent.
-
getName
public java.lang.String getName()
Returns the name of this logger.- Returns:
- the name of this logger, may be
null.
-
error
public void error(java.lang.String message)
Description copied from interface:LoggerLogs a message at the ERROR level.
-
warn
public void warn(java.lang.String message)
Description copied from interface:LoggerLogs a message at the WARN level.
-
info
public void info(java.lang.String message)
Description copied from interface:LoggerLogs a message at the INFO level.
-
debug
public void debug(java.lang.String message)
Description copied from interface:LoggerLogs a message at the DEBUG level.
-
isErrorEnabled
public boolean isErrorEnabled()
Description copied from interface:LoggerIndicates whether logging is enabled at the ERROR level.- Specified by:
isErrorEnabledin interfaceLogger- Returns:
trueif logging is enabled at the ERROR level, otherwisefalse.
-
setErrorEnabled
public void setErrorEnabled(boolean errorEnabled)
Sets whether logging is enabled at the ERROR level.- Parameters:
errorEnabled- determines whether logging is enabled at the ERROR level.
-
isWarnEnabled
public boolean isWarnEnabled()
Description copied from interface:LoggerIndicates whether logging is enabled at the WARN level.- Specified by:
isWarnEnabledin interfaceLogger- Returns:
trueif logging is enabled at the WARN level, otherwisefalse.
-
setWarnEnabled
public void setWarnEnabled(boolean warnEnabled)
Sets whether logging is enabled at the WARN level.- Parameters:
warnEnabled- determines whether logging is enabled at the WARN level.
-
isInfoEnabled
public boolean isInfoEnabled()
Description copied from interface:LoggerIndicates whether logging is enabled at the INFO level.- Specified by:
isInfoEnabledin interfaceLogger- Returns:
trueif logging is enabled at the INFO level, otherwisefalse.
-
setInfoEnabled
public void setInfoEnabled(boolean infoEnabled)
Sets whether logging is enabled at the INFO level.- Parameters:
infoEnabled- determines whether logging is enabled at the INFO level.
-
isDebugEnabled
public boolean isDebugEnabled()
Description copied from interface:LoggerIndicates whether logging is enabled at the DEBUG level.- Specified by:
isDebugEnabledin interfaceLogger- Returns:
trueif logging is enabled at the DEBUG level, otherwisefalse.
-
setDebugEnabled
public void setDebugEnabled(boolean debugEnabled)
Sets whether logging is enabled at the DEBUG level.- Parameters:
debugEnabled- determines whether logging is enabled at the DEBUG level.
-
log
protected void log(java.lang.String level, java.lang.String message)Logs the specified message at the specified level.This method is called internally by the
error(String),warn(String),info(String)anddebug(String)methods, with thelevelargument set to the text "ERROR", "WARN", "INFO", or "DEBUG" respectively.The default implementation of this method sends the the output of
BasicLogFormatter.format(level,message,getName())to theWriterspecified in the class constructor, and then flushes it.Overriding this method in a subclass provides a convenient means of logging to a
Writerusing a different format.- Parameters:
level- a string representing the level of the log message.message- the message to log.
-
-