Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concept of mapping functions along with a RemoveNew… #273

Merged
merged 7 commits into from Jan 24, 2020
Merged

Conversation

alwyn
Copy link
Contributor

@alwyn alwyn commented Jan 22, 2020

…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.

…LinesMapper implementations that can be used by a MappingLogEventWriter.
Alwyn Schoeman added 6 commits January 23, 2020 16:57
…narios, including being called twice.

MappingLogEventWriter setPrintStream modified to cater for different scenarios, including being called twice.

MappingLogEventWriter stream handling simplified by keeping p as the original set PrintStream and treating the CaptureStream as separate.
… optional combine spaces in LogEvents.

This differs from using RemoveNewLinesMapper in the MappingLogEventWriter in that it modifies the LogEvent returning a FrozenLogEvent instead of modifying the data just before writing to the output.

This listener thus doesn't write to output, but similarly to the ProtectionLogListener, modifies the LogEvent that is processed by subsequent LogListeners defined in the LoggerAdapter.
Will be parked in another changelist for future consideration
@alwyn alwyn changed the title Concept of mapping functions along with ProtectLogEvent and RemoveNew… Concept of mapping functions along with a RemoveNew… Jan 24, 2020
@ar ar merged commit 9893d51 into jpos:master Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants