Add ability to not use a Global Tag
Hi, Is it possible to not use a Global Tag? I tried inserting an empty string or null like so:
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.tag("")
.build();
for the format strategy, but the final output appends a dash character with the local tag like so: "D/ -MyLocalTag"
Looking at the source I think this happens because of this method:
private String formatTag(String tag) {
if (!Utils.isEmpty(tag) && !Utils.equals(this.tag, tag)) {
return this.tag + "-" + tag;
}
return this.tag;
}
I clone it and just change one line:
private String formatTag(String tag) {
if (!Utils.isEmpty(tag) && !Utils.equals(this.tag, tag)) {
//return this.tag + "-" + tag;
return this.tag + tag;
}
return this.tag;
}
so that you can use
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.tag("GlobalTag")
.build();
I recommend not to use LocalTag, this will make the log show the code line number where you init Logger but not where it real used.
I hope that the author can modify the code as I do, even if the user wants to use -, the user can add their own rather than always have a -.
like this:
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.tag("GlobalTag-")
.build();
👍 I see the issue. Definitely this can be improved. For the time being, you can actually modify tag as you like by providing a custom LogStrategy
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.tag("")
.logStrategy((priority, tag, message) -> {
String newTag = tag.subSequence(1, tag.length()).toString();
Log.println(priority, newTag, message);
})
.build();
Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
Logger.t("LocalTag").d("test");
This will print out D/LocalTag: