Class MappingLogEventWriter
java.lang.Object
org.jpos.util.BaseLogEventWriter
org.jpos.util.MappingLogEventWriter
- All Implemented Interfaces:
XmlConfigurable, LogEventWriter
LogEventWriter that can be configured with event and output mappers to modify
the events before writing to output stream and modify the output stream before writing
to the final destination respectfully.
Example configuration:
<writer class="org.jpos.util.MappingLogEventWriter">
<event-mapper class="...">
<property.... />
</event-mapper>
<event-mapper class="..."/>
<output-mapper class="...">
<property.... />
</output-mapper>
<output-mapper class="..."/>
</writer>
- Since:
- 2.1.4
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a writer with no mappers configured; mappers are wired bysetConfiguration(Element). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the writer and releases any underlying resources.protected voidLazily allocates the capture stream pair when at least one output mapper is configured.protected voidconfigureEventMappers(org.jdom2.Element e) Reads<event-mapper>children fromeand instantiates each.protected voidconfigureOutputMappers(org.jdom2.Element e) Reads<output-mapper>children fromeand instantiates each.protected voidThis method exists and is used so that we can verify the order of instructions during a call to write in unit tests.protected LogEventApplies every registered event mapper, in order, toev.protected byte[]mapOutput(byte[] output) Applies every registered output mapper, in order, to the captured output bytes.voidsetConfiguration(org.jdom2.Element e) Configures this object from an XML element.voidSets the print stream used for output.voidWrites a log event to the underlying output.protected voidWrite to capture print stream when defined.
-
Constructor Details
-
MappingLogEventWriter
public MappingLogEventWriter()Creates a writer with no mappers configured; mappers are wired bysetConfiguration(Element).
-
-
Method Details
-
setPrintStream
Description copied from interface:LogEventWriterSets the print stream used for output.- Specified by:
setPrintStreamin interfaceLogEventWriter- Overrides:
setPrintStreamin classBaseLogEventWriter- Parameters:
p- the destination stream
-
close
Description copied from interface:LogEventWriterCloses the writer and releases any underlying resources.- Specified by:
closein interfaceLogEventWriter- Overrides:
closein classBaseLogEventWriter
-
write
Description copied from interface:LogEventWriterWrites a log event to the underlying output.- Specified by:
writein interfaceLogEventWriter- Overrides:
writein classBaseLogEventWriter- Parameters:
ev- the log event to write
-
setConfiguration
Description copied from interface:XmlConfigurableConfigures this object from an XML element.- Specified by:
setConfigurationin interfaceXmlConfigurable- Parameters:
e- Configuration element- Throws:
ConfigurationException- on error
-
configureCaptureStreams
Lazily allocates the capture stream pair when at least one output mapper is configured. -
configureEventMappers
Reads<event-mapper>children fromeand instantiates each.- Parameters:
e- XML configuration element- Throws:
ConfigurationException- if any mapper class cannot be instantiated or configured
-
configureOutputMappers
Reads<output-mapper>children fromeand instantiates each.- Parameters:
e- XML configuration element- Throws:
ConfigurationException- if any mapper class cannot be instantiated or configured
-
mapEvents
-
mapOutput
Applies every registered output mapper, in order, to the captured output bytes.- Parameters:
output- bytes captured fromwriteToCaptureStream(LogEvent)- Returns:
- the transformed output bytes
-
delegateWriteToSuper
This method exists and is used so that we can verify the order of instructions during a call to write in unit tests.- Parameters:
ev- LogEvent to write.
-
writeToCaptureStream
Write to capture print stream when defined.- Parameters:
ev- LogEvent to write.
-