AndroidLogAdapter.java
1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.wd.base.log;
import static com.wd.base.log.Utils.checkNotNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* Android terminal log output implementation for {@link LogAdapter}.
* Prints output to LogCat with pretty borders.
*
* <pre>
* ┌──────────────────────────
* │ Method stack history
* ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
* │ Log message
* └──────────────────────────
* </pre>
*/
public class AndroidLogAdapter implements LogAdapter {
@NonNull
private final FormatStrategy formatStrategy;
public AndroidLogAdapter() {
this.formatStrategy = PrettyFormatStrategy.newBuilder().build();
}
public AndroidLogAdapter(@NonNull FormatStrategy formatStrategy) {
this.formatStrategy = checkNotNull(formatStrategy);
}
@Override
public boolean isLoggable(int priority, @Nullable String tag) {
return true;
}
@Override
public void log(int priority, @Nullable String tag, @NonNull String message) {
formatStrategy.log(priority, tag, message);
}
}