Skip to content

Commit 43e83b7

Browse files
authored
avoid logging empty lines, so removing complete log lines becomes possible (#2)
1 parent e68bad9 commit 43e83b7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/java/com/tsystems/sbs/LogFileFilterOutputStream.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class LogFileFilterOutputStream extends LineTransformationOutputStream {
3232
private final List<RegexpPair> defaultRegexpPairs;
3333
private final List<RegexpPair> customRegexpPairs;
3434
private final String jobName;
35+
36+
private final Pattern AT_LEAST_ONE_NON_WHITESPACE_PATTERN = Pattern.compile(".*\\S.*\\r?\\n?");
3537

3638

3739
public LogFileFilterOutputStream(OutputStream out, Charset charset, String jobName, LogFileFilterConfig config) {
@@ -100,7 +102,10 @@ protected void eol(byte[] bytes, int len) throws IOException {
100102
LOGGER.log(Level.FINE,
101103
"Filtered logfile for {0} output ''{1}''.", new Object[]{jobName, line});
102104
}
103-
logger.write(line.getBytes(charset));
105+
106+
if (AT_LEAST_ONE_NON_WHITESPACE_PATTERN.matcher(line).matches()) {
107+
logger.write(line.getBytes(charset));
108+
}
104109
} else {
105110
// no change, write the bytes as-is to avoid messing with the encoding
106111
logger.write(bytes, 0, len);

0 commit comments

Comments
 (0)