Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Only log color to System.out
Browse files Browse the repository at this point in the history
  • Loading branch information
powersagitar committed Jan 11, 2025
1 parent e125961 commit 9c6c196
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public enum Severity {
ERROR, ANSIColor.RED,
FATAL, ANSIColor.RED_BACKGROUND
);

@Override
public String toString() {
return ANSIColor.colorize(colorMap.get(this), super.toString());
}
}

private Severity level = Severity.INFO;
Expand Down Expand Up @@ -76,11 +71,15 @@ private void log(final Severity severity, final String msg) {

final Instant now = Instant.now();

final String formattedMsg = String.format("[%s][%s] %s%n", now.toString(), severity, msg);

for (OutputStream sink : sinks) {
try {
sink.write(formattedMsg.getBytes());
final String severityStr = sink == System.out ?
ANSIColor.colorize(Severity.colorMap.get(severity), severity.toString()) :
severity.toString();

final String formattedMessage = String.format("[%s][%s] %s%n", now.toString(), severityStr, msg);

sink.write(formattedMessage.getBytes());
} catch (final IOException e) {
System.err.println(e.getMessage());
}
Expand Down

0 comments on commit 9c6c196

Please sign in to comment.