Package com.puppycrawl.tools.checkstyle
Class DefaultLogger
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
-
- com.puppycrawl.tools.checkstyle.DefaultLogger
-
- All Implemented Interfaces:
AuditListener
,Configurable
,Contextualizable
,EventListener
public class DefaultLogger extends AbstractAutomaticBean 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description static String
ADD_EXCEPTION_MESSAGE
A key pointing to the add exception message in the "messages.properties" file.static String
AUDIT_FINISHED_MESSAGE
A key pointing to the finished audit message in the "messages.properties" file.static String
AUDIT_STARTED_MESSAGE
A key pointing to the started audit message in the "messages.properties" file.private boolean
closeError
Close error stream after use.private boolean
closeInfo
Close info stream after use.private PrintWriter
errorWriter
Where to write error messages.private AuditEventFormatter
formatter
Formatter for the log message.private PrintWriter
infoWriter
Where to write info messages.
-
Constructor Summary
Constructors Constructor Description DefaultLogger(OutputStream outputStream, AbstractAutomaticBean.OutputStreamOptions outputStreamOptions)
Creates a newDefaultLogger
instance.DefaultLogger(OutputStream infoStream, AbstractAutomaticBean.OutputStreamOptions infoStreamOptions, OutputStream errorStream, AbstractAutomaticBean.OutputStreamOptions errorStreamOptions)
Creates a newDefaultLogger
instance.DefaultLogger(OutputStream infoStream, AbstractAutomaticBean.OutputStreamOptions infoStreamOptions, OutputStream errorStream, AbstractAutomaticBean.OutputStreamOptions errorStreamOptions, AuditEventFormatter messageFormatter)
Creates a newDefaultLogger
instance.DefaultLogger(OutputStream outputStream, AutomaticBean.OutputStreamOptions outputStreamOptions)
Creates a newDefaultLogger
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addError(AuditEvent event)
Print an Emacs compliant line on the error stream.void
addException(AuditEvent event, Throwable throwable)
Notify that an exception happened while performing audit.void
auditFinished(AuditEvent event)
Notify that the audit is finished.void
auditStarted(AuditEvent event)
Notify that the audit is about to start.private void
closeStreams()
Flushes the output streams and closes them if needed.void
fileFinished(AuditEvent event)
Notify that audit is finished on a specific file.void
fileStarted(AuditEvent event)
Notify that audit is about to start on a specific file.protected void
finishLocalSetup()
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.-
Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Field Detail
-
ADD_EXCEPTION_MESSAGE
public static final 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 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 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 PrintWriter infoWriter
Where to write info messages.
-
closeInfo
private final boolean closeInfo
Close info stream after use.
-
errorWriter
private final 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(OutputStream outputStream, AutomaticBean.OutputStreamOptions outputStreamOptions)
Creates a newDefaultLogger
instance.- Parameters:
outputStream
- where to log audit eventsoutputStreamOptions
- ifCLOSE
that should be closed in auditFinished()
-
DefaultLogger
public DefaultLogger(OutputStream outputStream, AbstractAutomaticBean.OutputStreamOptions outputStreamOptions)
Creates a newDefaultLogger
instance.- Parameters:
outputStream
- where to log audit eventsoutputStreamOptions
- ifCLOSE
that should be closed in auditFinished()
-
DefaultLogger
public DefaultLogger(OutputStream infoStream, AbstractAutomaticBean.OutputStreamOptions infoStreamOptions, OutputStream errorStream, AbstractAutomaticBean.OutputStreamOptions errorStreamOptions)
Creates a newDefaultLogger
instance.- Parameters:
infoStream
- theOutputStream
for info messages.infoStreamOptions
- ifCLOSE
info should be closed in auditFinished()errorStream
- theOutputStream
for error messages.errorStreamOptions
- ifCLOSE
error should be closed in auditFinished()
-
DefaultLogger
public DefaultLogger(OutputStream infoStream, AbstractAutomaticBean.OutputStreamOptions infoStreamOptions, OutputStream errorStream, AbstractAutomaticBean.OutputStreamOptions errorStreamOptions, AuditEventFormatter messageFormatter)
Creates a newDefaultLogger
instance.- Parameters:
infoStream
- theOutputStream
for info messagesinfoStreamOptions
- ifCLOSE
info should be closed in auditFinished()errorStream
- theOutputStream
for error messageserrorStreamOptions
- ifCLOSE
error should be closed in auditFinished()messageFormatter
- formatter for the log message.- Throws:
IllegalArgumentException
- if stream options are null
-
-
Method Detail
-
finishLocalSetup
protected void finishLocalSetup()
Description copied from class:AbstractAutomaticBean
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.The default implementation does nothing.
- Specified by:
finishLocalSetup
in classAbstractAutomaticBean
-
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:
addError
in interfaceAuditListener
- Parameters:
event
- the event details- See Also:
AuditListener
-
addException
public void addException(AuditEvent event, Throwable throwable)
Description copied from interface:AuditListener
Notify that an exception happened while performing audit.- Specified by:
addException
in interfaceAuditListener
- Parameters:
event
- the event detailsthrowable
- details of the exception
-
auditStarted
public void auditStarted(AuditEvent event)
Description copied from interface:AuditListener
Notify that the audit is about to start.- Specified by:
auditStarted
in interfaceAuditListener
- Parameters:
event
- the event details
-
auditFinished
public void auditFinished(AuditEvent event)
Description copied from interface:AuditListener
Notify that the audit is finished.- Specified by:
auditFinished
in interfaceAuditListener
- Parameters:
event
- the event details
-
fileStarted
public void fileStarted(AuditEvent event)
Description copied from interface:AuditListener
Notify that audit is about to start on a specific file.- Specified by:
fileStarted
in interfaceAuditListener
- Parameters:
event
- the event details
-
fileFinished
public void fileFinished(AuditEvent event)
Description copied from interface:AuditListener
Notify that audit is finished on a specific file.- Specified by:
fileFinished
in interfaceAuditListener
- Parameters:
event
- the event details
-
closeStreams
private void closeStreams()
Flushes the output streams and closes them if needed.
-
-