Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -410,16 +411,15 @@ static Slf4jLogMessageContext parseSlf4jContextFromLogMessage(String logMessage)
public void addLogMessageConsumer(Consumer<String> consumer) {
checkNotNull(consumer, "consumer parameter is NULL!");
addOutPutStream(new OutputStream() {
StringBuilder lineBuilder = new StringBuilder();
private ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the property be final?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes , final is better


@Override
public void write(int chr) {
try {
lineBuilder.append((char) chr);
Matcher matcher = LOG_MESSAGE_PATTERN.matcher(lineBuilder.toString());
if (matcher.matches()) {
consumer.accept(matcher.group(1));
lineBuilder = new StringBuilder();
outputStream.write(chr);
if ((chr == '\n')) {
consumer.accept(outputStream.toString());
outputStream.reset();
}
} catch (Exception e) {
// log error and continue
Expand Down