Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 6e3a4f1

Browse files
committed
Don't print empty tags in DefaultLogger messages
1 parent 300b67c commit 6e3a4f1

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Clog/src/main/java/com/caseyjbrooks/clog/Clog.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public static ClogProfile tag(String tag) {
9898
return getInstance().tag(tag);
9999
}
100100

101+
public static ClogProfile noTag() {
102+
return getInstance().tag(null);
103+
}
104+
101105
// Generic key-valued logging calls
102106
//--------------------------------------------------------------------------------------------------
103107

Clog/src/main/java/com/caseyjbrooks/clog/DefaultLogger.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public boolean isActive() {
3636

3737
@Override
3838
public int log(String tag, String message) {
39-
AnsiConsole.out.println(getAnsiLevelString().a(tag + ": ").a(message));
39+
AnsiConsole.out.println(getAnsiLevelString().a(getTagString(tag)).a(message));
4040
return 0;
4141
}
4242

4343
@Override
4444
public int log(String tag, String message, Throwable throwable) {
45-
AnsiConsole.out.println(getAnsiLevelString().a(tag + ": ").a(message).a(" (" + throwable.getMessage() + ")"));
45+
AnsiConsole.out.println(getAnsiLevelString().a(getTagString(tag)).a(message).a(getThrowableString(throwable)));
4646
return 0;
4747
}
4848

@@ -74,4 +74,17 @@ Ansi getAnsiLevelString() {
7474

7575
return Ansi.ansi();
7676
}
77+
78+
private String getTagString(String tag) {
79+
if(tag != null && tag.length() > 0) {
80+
return tag + ": ";
81+
}
82+
else {
83+
return "";
84+
}
85+
}
86+
87+
private String getThrowableString(Throwable throwable) {
88+
return " (" + throwable.getMessage() + ")";
89+
}
7790
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
version: '2.0.4'
3+
---
4+
5+
- Don't print empty tags in DefaultLogger messages

0 commit comments

Comments
 (0)