Package com.puppycrawl.tools.checkstyle
Class XMLLogger
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.XMLLogger
- All Implemented Interfaces:
AuditListener
,Configurable
,Contextualizable
,EventListener
Simple XML logger.
It outputs everything in UTF-8 (default XML encoding is UTF-8) in case
we want to localize error messages or simply that file names are
localized and takes care about escaping as well.
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static final class
The registered file messages.Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final int
Decimal radix.private static final int
Hex radix.private final boolean
Close output stream in auditFinished.private static final String[]
Some known entities to detect.private final Map<String,
XMLLogger.FileMessages> Holds all messages for the given file.private final PrintWriter
Helper writer that allows easy encoding and printing.private final Object
The writer lock object. -
Constructor Summary
ConstructorDescriptionXMLLogger
(OutputStream outputStream, AbstractAutomaticBean.OutputStreamOptions outputStreamOptions) Creates a newXMLLogger
instance.XMLLogger
(OutputStream outputStream, AutomaticBean.OutputStreamOptions outputStreamOptions) Creates a newXMLLogger
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addError
(AuditEvent event) Notify that an audit error was discovered on a specific file.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.static String
Escape <, > & ' and " as their entities.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
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.static boolean
isReference
(String ent) Finds whether the given argument is character or entity reference.private void
writeException
(Throwable throwable) Writes the exception event to the print writer.private void
Prints the "file" closing tag.private void
writeFileError
(AuditEvent event) Outputs the given event to the writer.private void
writeFileMessages
(String fileName, XMLLogger.FileMessages messages) Prints the file section with all file errors and exceptions.private void
writeFileOpeningTag
(String fileName) Prints the "file" opening tag with the given filename.Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
BASE_10
Decimal radix.- See Also:
-
BASE_16
Hex radix.- See Also:
-
ENTITIES
Some known entities to detect. -
closeStream
Close output stream in auditFinished. -
writerLock
The writer lock object. -
fileMessages
Holds all messages for the given file. -
writer
Helper writer that allows easy encoding and printing.
-
-
Constructor Details
-
XMLLogger
Creates a newXMLLogger
instance. Sets the output to a defined stream.- Parameters:
outputStream
- the stream to write logs to.outputStreamOptions
- ifCLOSE
stream should be closed in auditFinished()- Throws:
IllegalArgumentException
- if outputStreamOptions is null.
-
XMLLogger
public XMLLogger(OutputStream outputStream, AbstractAutomaticBean.OutputStreamOptions outputStreamOptions) Creates a newXMLLogger
instance. Sets the output to a defined stream.- Parameters:
outputStream
- the stream to write logs to.outputStreamOptions
- ifCLOSE
stream should be closed in auditFinished()- Throws:
IllegalArgumentException
- if outputStreamOptions is null.
-
-
Method Details
-
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
-
auditStarted
Description copied from interface:AuditListener
Notify that the audit is about to start.- Specified by:
auditStarted
in interfaceAuditListener
- Parameters:
event
- the event details
-
auditFinished
Description copied from interface:AuditListener
Notify that the audit is finished.- Specified by:
auditFinished
in interfaceAuditListener
- Parameters:
event
- the event details
-
fileStarted
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
Description copied from interface:AuditListener
Notify that audit is finished on a specific file.- Specified by:
fileFinished
in interfaceAuditListener
- Parameters:
event
- the event details
-
writeFileMessages
Prints the file section with all file errors and exceptions.- Parameters:
fileName
- The file name, as should be printed in the opening file tag.messages
- The file messages.
-
writeFileOpeningTag
Prints the "file" opening tag with the given filename.- Parameters:
fileName
- The filename to output.
-
writeFileClosingTag
Prints the "file" closing tag. -
addError
Description copied from interface:AuditListener
Notify that an audit error was discovered on a specific file.- Specified by:
addError
in interfaceAuditListener
- Parameters:
event
- the event details
-
writeFileError
Outputs the given event to the writer.- Parameters:
event
- An event to print.
-
addException
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
-
writeException
Writes the exception event to the print writer.- Parameters:
throwable
- The
-
encode
Escape <, > & ' and " as their entities.- Parameters:
value
- the value to escape.- Returns:
- the escaped value if necessary.
-
isReference
Finds whether the given argument is character or entity reference.- Parameters:
ent
- the possible entity to look for.- Returns:
- whether the given argument a character or entity reference
-