Package com.puppycrawl.tools.checkstyle
Class DefaultLogger
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.DefaultLogger
-
- All Implemented Interfaces:
AuditListener,Configurable,Contextualizable,java.util.EventListener
public class DefaultLogger extends AutomaticBean implements AuditListener
Simple plain logger for text output. This is maybe not very suitable for a text output into a file since it does not need all 'audit finished' and so on stuff, but it looks good on stdout anyway. If there is really a problem this is what XMLLogger is for. It gives structure.- See Also:
XMLLogger
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringADD_EXCEPTION_MESSAGEA key pointing to the add exception message in the "messages.properties" file.static java.lang.StringAUDIT_FINISHED_MESSAGEA key pointing to the finished audit message in the "messages.properties" file.static java.lang.StringAUDIT_STARTED_MESSAGEA key pointing to the started audit message in the "messages.properties" file.private booleancloseErrorClose error stream after use.private booleancloseInfoClose info stream after use.private java.io.PrintWritererrorWriterWhere to write error messages.private AuditEventFormatterformatterFormatter for the log message.private java.io.PrintWriterinfoWriterWhere to write info messages.
-
Constructor Summary
Constructors Constructor Description DefaultLogger(java.io.OutputStream outputStream, boolean closeStreamsAfterUse)Creates a newDefaultLoggerinstance.DefaultLogger(java.io.OutputStream infoStream, boolean closeInfoAfterUse, java.io.OutputStream errorStream, boolean closeErrorAfterUse)Creates a newDefaultLoggerinstance.DefaultLogger(java.io.OutputStream infoStream, boolean closeInfoAfterUse, java.io.OutputStream errorStream, boolean closeErrorAfterUse, AuditEventFormatter messageFormatter)Creates a newDefaultLoggerinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddError(AuditEvent event)Print an Emacs compliant line on the error stream.voidaddException(AuditEvent event, java.lang.Throwable throwable)Notify that an exception happened while performing audit.voidauditFinished(AuditEvent event)Notify that the audit is finished.voidauditStarted(AuditEvent event)Notify that the audit is about to start.private voidcloseStreams()Flushes the output streams and closes them if needed.voidfileFinished(AuditEvent event)Notify that audit is finished on a specific file.voidfileStarted(AuditEvent event)Notify that audit is about to start on a specific file.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
-
-
-
-
Field Detail
-
ADD_EXCEPTION_MESSAGE
public static final java.lang.String ADD_EXCEPTION_MESSAGE
A key pointing to the add exception message in the "messages.properties" file.- See Also:
- Constant Field Values
-
AUDIT_STARTED_MESSAGE
public static final java.lang.String AUDIT_STARTED_MESSAGE
A key pointing to the started audit message in the "messages.properties" file.- See Also:
- Constant Field Values
-
AUDIT_FINISHED_MESSAGE
public static final java.lang.String AUDIT_FINISHED_MESSAGE
A key pointing to the finished audit message in the "messages.properties" file.- See Also:
- Constant Field Values
-
infoWriter
private final java.io.PrintWriter infoWriter
Where to write info messages.
-
closeInfo
private final boolean closeInfo
Close info stream after use.
-
errorWriter
private final java.io.PrintWriter errorWriter
Where to write error messages.
-
closeError
private final boolean closeError
Close error stream after use.
-
formatter
private final AuditEventFormatter formatter
Formatter for the log message.
-
-
Constructor Detail
-
DefaultLogger
public DefaultLogger(java.io.OutputStream outputStream, boolean closeStreamsAfterUse)Creates a newDefaultLoggerinstance.- Parameters:
outputStream- where to log infos and errorscloseStreamsAfterUse- if oS should be closed in auditFinished()
-
DefaultLogger
public DefaultLogger(java.io.OutputStream infoStream, boolean closeInfoAfterUse, java.io.OutputStream errorStream, boolean closeErrorAfterUse)Creates a newDefaultLoggerinstance.- Parameters:
infoStream- theOutputStreamfor info messages.closeInfoAfterUse- auditFinished should close infoStream.errorStream- theOutputStreamfor error messages.closeErrorAfterUse- auditFinished should close errorStream
-
DefaultLogger
public DefaultLogger(java.io.OutputStream infoStream, boolean closeInfoAfterUse, java.io.OutputStream errorStream, boolean closeErrorAfterUse, AuditEventFormatter messageFormatter)Creates a newDefaultLoggerinstance.- Parameters:
infoStream- theOutputStreamfor info messagescloseInfoAfterUse- auditFinished should close infoStreamerrorStream- theOutputStreamfor error messagescloseErrorAfterUse- auditFinished should close errorStreammessageFormatter- formatter for the log message.
-
-
Method Detail
-
addError
public void addError(AuditEvent event)
Print an Emacs compliant line on the error stream. If the column number is non zero, then also display it.- Specified by:
addErrorin interfaceAuditListener- Parameters:
event- the event details- See Also:
AuditListener
-
addException
public void addException(AuditEvent event, java.lang.Throwable throwable)
Description copied from interface:AuditListenerNotify that an exception happened while performing audit.- Specified by:
addExceptionin interfaceAuditListener- Parameters:
event- the event detailsthrowable- details of the exception
-
auditStarted
public void auditStarted(AuditEvent event)
Description copied from interface:AuditListenerNotify that the audit is about to start.- Specified by:
auditStartedin interfaceAuditListener- Parameters:
event- the event details
-
auditFinished
public void auditFinished(AuditEvent event)
Description copied from interface:AuditListenerNotify that the audit is finished.- Specified by:
auditFinishedin interfaceAuditListener- Parameters:
event- the event details
-
fileStarted
public void fileStarted(AuditEvent event)
Description copied from interface:AuditListenerNotify that audit is about to start on a specific file.- Specified by:
fileStartedin interfaceAuditListener- Parameters:
event- the event details
-
fileFinished
public void fileFinished(AuditEvent event)
Description copied from interface:AuditListenerNotify that audit is finished on a specific file.- Specified by:
fileFinishedin interfaceAuditListener- Parameters:
event- the event details
-
closeStreams
private void closeStreams()
Flushes the output streams and closes them if needed.
-
-