Skip to content

Commit

Permalink
Properly synchronize access so we do not risk having a timestamp in t…
Browse files Browse the repository at this point in the history
…he middle of a line.
  • Loading branch information
jglick committed Oct 25, 2018
1 parent 9b19c6e commit bf1e61c
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ public OutputStream decorate(final OutputStream logger) throws IOException, Inte
return new LineTransformationOutputStream() {
@Override
protected void eol(byte[] b, int len) throws IOException {
logger.write('[');
logger.write(f.format(new Date()).getBytes(StandardCharsets.US_ASCII));
logger.write(']');
logger.write(' ');
logger.write(b, 0, len);
synchronized (logger) { // typically this will be a PrintStream
logger.write('[');
logger.write(f.format(new Date()).getBytes(StandardCharsets.US_ASCII));
logger.write(']');
logger.write(' ');
logger.write(b, 0, len);
}
}
};
}
Expand Down

0 comments on commit bf1e61c

Please sign in to comment.