-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More accurate log processing. (#643)
* More accurate log processing. The Docker logs can come in non normalized form. The line breaks can be not at end of line, the frame's boundary can split multibyte unicode symbols in the middle and so on. This patch address this problems and normalize logs so, that they can be processed strictly line by line. To achive this, the extra base class BaseConsumer have been added. That class normalize the incoming in method accept() logs and forward it to method process() for it's child classes. Other *Consumer classes have been reworked to be child to the BaseConsumer class and only do own work. Adititionally, BaseConsumer have new withRemoveAnsiCodes(boolean) method for ability to disable ANSI color codes removing (true by default). * Move normalization logic directly to FrameConsumerResultCallback It's help to not ruin the API of *Consumer classes. * Added some tests for log normalization in class FrameConsumerResultCallback. * Fix Codacity warning * More test for the FrameConsumerResultCallback class * Stabilize tests * Log consumers, that not derive BaseConsumer class, is not receive color codes now. Added record to the changelog. * One more test for FrameConsumerResultCallback class. * Fixes due to the code review recommendations * Fixes due to the code review recommendations (Part 2) * One more use case for FrameConsumerResultCallback class. And unit test for it. If StreamType is STDERR or STDOUT the log always have newline at line end. Therefore preprocessor should trim it to be consistent with RAW type processing. * Roll back previouse change doe to failing tests. Doing newline trimming directly in Slf4jLogConsumer class. * Fixes due to the code review recommendations (Part 3)
- Loading branch information
Showing
7 changed files
with
319 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/java/org/testcontainers/containers/output/BaseConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.testcontainers.containers.output; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public abstract class BaseConsumer<SELF extends BaseConsumer<SELF>> implements Consumer<OutputFrame> { | ||
@Getter | ||
@Setter | ||
private boolean removeColorCodes = true; | ||
|
||
public SELF withRemoveAnsiCodes(boolean removeAnsiCodes) { | ||
this.removeColorCodes = removeAnsiCodes; | ||
return (SELF) this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.