Skip to content

Commit

Permalink
avoid logging empty lines, so removing complete log lines becomes pos…
Browse files Browse the repository at this point in the history
…sible (#2)
  • Loading branch information
TorstenKruse authored Nov 5, 2021
1 parent e68bad9 commit 43e83b7
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class LogFileFilterOutputStream extends LineTransformationOutputStream {
private final List<RegexpPair> defaultRegexpPairs;
private final List<RegexpPair> customRegexpPairs;
private final String jobName;

private final Pattern AT_LEAST_ONE_NON_WHITESPACE_PATTERN = Pattern.compile(".*\\S.*\\r?\\n?");


public LogFileFilterOutputStream(OutputStream out, Charset charset, String jobName, LogFileFilterConfig config) {
Expand Down Expand Up @@ -100,7 +102,10 @@ protected void eol(byte[] bytes, int len) throws IOException {
LOGGER.log(Level.FINE,
"Filtered logfile for {0} output ''{1}''.", new Object[]{jobName, line});
}
logger.write(line.getBytes(charset));

if (AT_LEAST_ONE_NON_WHITESPACE_PATTERN.matcher(line).matches()) {
logger.write(line.getBytes(charset));
}
} else {
// no change, write the bytes as-is to avoid messing with the encoding
logger.write(bytes, 0, len);
Expand Down

0 comments on commit 43e83b7

Please sign in to comment.