Concept of mapping functions along with a RemoveNew… #273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…LinesMapper implementatios that can be used by a MappingLogEventWriter. Additionally the addition of a FlatLogListener to achieve similar result without using the MappingLogEventWriter.
Goal
Provide the ability to modify LogEvents before they are dumped and the output of a dumped LogEvent before it is written to the output stream.
Design
Introduce the concept of Mappers that extend Java's Function interface.
These mappers map from a version of one type to a modified version of the same type.
E.g. LogEventMapper maps a LogEvent to a modified LogEvent.
ByteArrayMapper maps a byte[] to a modified byte[]
These mappers can then be chained in a LogEventWriter to allow flexible control over log output.
Implementation
A MappingLogEventWriter is added that can be configured with multiple event-mappers and output-mappers. The event-mappers are LogEventMappers for pre-dump modification of LogEvents. The output-mappers are ByteArrayMappers for post-dump modification of the output stream.
In the event that output-mappers are defined, the original PrintStream is hijacked to capture the dumped data, the data is modified and then replayed to the intended target PrintStream.
NB. Note that a log-listener that uses a MappingLogEventWriter to modify LogEvents will pass the changes on to subsequent log-listeners since the LoggerAdaptor passes the processed LogEvents from listener to listener.
The RemoveNewLinesMapper has been added as an output mapper to remove newlines and optionally consolidate multiple spaces into a single space. By default this mapper will add a newline at the end of the LogEvent after all have been removed. This mapper is important in Cloud environments where logparsers have difficulty in determining where a log message starts and where it ends.
All the mappers have been added to a new package org.jpos.util.function since the expectation is that there will be more core functionality that could be implemented as functions.
FlatLogListener
Additionally FlatLogListener has been added to provide the RemoveNewLinesMapper functionality without using the MappingLogEventWriter. Note that using this listener will impact all subsequently defined LogListeners in the LoggerAdaptor configuration.