Skip to content

Commit 947a722

Browse files
author
wanghai
committed
only open LogKit
1 parent 0e396b6 commit 947a722

19 files changed

+231
-242
lines changed

log/src/main/java/com/kit/log/ui/LogAdapter.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import android.widget.TextView
1414
import android.widget.Toast
1515
import androidx.recyclerview.widget.RecyclerView
1616
import com.kit.log.R
17-
import com.orhanobut.logger.Logger
1817
import com.orhanobut.logger.Utils
1918

2019
class LogAdapter : RecyclerView.Adapter<LogAdapter.VH>() {
@@ -83,23 +82,23 @@ class LogAdapter : RecyclerView.Adapter<LogAdapter.VH>() {
8382
itemView.findViewById<TextView>(R.id.tv_date).text = data.dateString
8483
itemView.findViewById<TextView>(R.id.tv_msg).text = data.message
8584
val color = when (Utils.logLevel(data.priority)) {
86-
Logger.VERBOSE -> {
85+
Utils.VERBOSE -> {
8786
itemView.resources.getColor(R.color.verbose)
8887
}
8988

90-
Logger.DEBUG -> {
89+
Utils.DEBUG -> {
9190
itemView.resources.getColor(R.color.debug)
9291
}
9392

94-
Logger.INFO -> {
93+
Utils.INFO -> {
9594
itemView.resources.getColor(R.color.info)
9695
}
9796

98-
Logger.WARN -> {
97+
Utils.WARN -> {
9998
itemView.resources.getColor(R.color.warning)
10099
}
101100

102-
Logger.ERROR -> {
101+
Utils.ERROR -> {
103102
itemView.resources.getColor(R.color.error)
104103
}
105104

log/src/main/java/com/kit/log/ui/LogViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.kit.log.ui
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5-
import com.kit.log.LogKit
5+
import com.orhanobut.logger.LogKit
66
import kotlinx.coroutines.Dispatchers
77
import kotlinx.coroutines.flow.*
88
import kotlinx.coroutines.launch

log/src/main/java/com/orhanobut/logger/AndroidLogAdapter.java

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/**
1010
* 针对 {@link LogAdapter} 的 Android 终端日志输出实现。
11-
*
11+
* <p>
1212
* 以漂亮的边框格式将日志输出到 LogCat。
1313
*
1414
* <pre>
@@ -19,43 +19,44 @@
1919
* └──────────────────────────
2020
* </pre>
2121
*/
22-
public class AndroidLogAdapter implements LogAdapter {
23-
24-
@NonNull private final FormatStrategy formatStrategy;
25-
26-
// 默认构造函数,使用 PrettyFormatStrategy 格式化策略
27-
public AndroidLogAdapter() {
28-
this.formatStrategy = PrettyFormatStrategy.newBuilder().build();
29-
}
30-
31-
// 构造函数,允许使用自定义的格式化策略
32-
public AndroidLogAdapter(@NonNull FormatStrategy formatStrategy) {
33-
this.formatStrategy = checkNotNull(formatStrategy);
34-
}
35-
36-
/**
37-
* 判断日志是否需要输出。
38-
*
39-
* @param priority 日志级别,例如 DEBUG、WARNING
40-
* @param tag 日志消息的标签
41-
* @return 是否需要输出日志,默认为始终输出 (返回 true)。
42-
*/
43-
@Override
44-
public boolean isLoggable(int priority, @Nullable String tag) {
45-
return true;
46-
}
47-
48-
/**
49-
* 根据格式化策略输出日志。
50-
*
51-
* @param priority 日志级别,例如 DEBUG、WARNING
52-
* @param tag 日志消息的标签
53-
* @param message 日志消息的具体内容
54-
*/
55-
@Override
56-
public void log(int priority, @Nullable String tag, @NonNull String message) {
57-
formatStrategy.log(priority, tag, message);
58-
}
22+
class AndroidLogAdapter implements LogAdapter {
23+
24+
@NonNull
25+
private final FormatStrategy formatStrategy;
26+
27+
// 默认构造函数,使用 PrettyFormatStrategy 格式化策略
28+
public AndroidLogAdapter() {
29+
this.formatStrategy = PrettyFormatStrategy.newBuilder().build();
30+
}
31+
32+
// 构造函数,允许使用自定义的格式化策略
33+
public AndroidLogAdapter(@NonNull FormatStrategy formatStrategy) {
34+
this.formatStrategy = checkNotNull(formatStrategy);
35+
}
36+
37+
/**
38+
* 判断日志是否需要输出。
39+
*
40+
* @param priority 日志级别,例如 DEBUG、WARNING
41+
* @param tag 日志消息的标签
42+
* @return 是否需要输出日志,默认为始终输出 (返回 true)。
43+
*/
44+
@Override
45+
public boolean isLoggable(int priority, @Nullable String tag) {
46+
return true;
47+
}
48+
49+
/**
50+
* 根据格式化策略输出日志。
51+
*
52+
* @param priority 日志级别,例如 DEBUG、WARNING
53+
* @param tag 日志消息的标签
54+
* @param message 日志消息的具体内容
55+
*/
56+
@Override
57+
public void log(int priority, @Nullable String tag, @NonNull String message) {
58+
formatStrategy.log(priority, tag, message);
59+
}
5960

6061
}
6162

log/src/main/java/com/orhanobut/logger/CsvFormatStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* 4. 标签
2525
* 5. 日志消息
2626
*/
27-
public class CsvFormatStrategy implements FormatStrategy {
27+
class CsvFormatStrategy implements FormatStrategy {
2828

2929
private static final String NEW_LINE = System.getProperty("line.separator");
3030
private static final String NEW_LINE_REPLACEMENT = " <br> ";

log/src/main/java/com/orhanobut/logger/DiskLogAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* 用于将日志消息保存到磁盘。
1111
* 默认情况下,它使用 {@link CsvFormatStrategy} 将文本消息转换为 CSV 格式。
1212
*/
13-
public class DiskLogAdapter implements LogAdapter {
13+
class DiskLogAdapter implements LogAdapter {
1414

1515
@NonNull private final FormatStrategy formatStrategy;
1616

log/src/main/java/com/orhanobut/logger/DiskLogStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* 将所有日志以 CSV 格式写入磁盘。
2121
*/
22-
public class DiskLogStrategy implements LogStrategy {
22+
class DiskLogStrategy implements LogStrategy {
2323

2424
@NonNull private final Handler handler;
2525

log/src/main/java/com/orhanobut/logger/DiskLogWriteReadStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.LinkedList;
2222
import java.util.List;
2323

24-
public class DiskLogWriteReadStrategy implements LogStrategy {
24+
class DiskLogWriteReadStrategy implements LogStrategy {
2525

2626
private static final int MAX_READ_LINES = 3000; // 最大可读3000 行
2727
private static final int MAX_BYTES = 500 * 1024; // 每个文件最大 500KB,约 4000 行

log/src/main/java/com/orhanobut/logger/FormatStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @see PrettyFormatStrategy
1010
* @see CsvFormatStrategy
1111
*/
12-
public interface FormatStrategy {
12+
interface FormatStrategy {
1313

1414
/**
1515
* 记录日志信息。

log/src/main/java/com/orhanobut/logger/LogAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @see AndroidLogAdapter
1010
* @see DiskLogAdapter
1111
*/
12-
public interface LogAdapter {
12+
interface LogAdapter {
1313

1414
/**
1515
* 用于判断日志是否需要输出。

log/src/main/java/com/kit/log/LogKit.kt renamed to log/src/main/java/com/orhanobut/logger/LogKit.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
package com.kit.log
1+
package com.orhanobut.logger
22

33
import android.app.Activity
44
import android.content.Context
55
import com.kit.log.ui.LogActivity.Companion.startActivity
6-
import com.orhanobut.logger.AndroidLogAdapter
7-
import com.orhanobut.logger.DiskLogAdapter
8-
import com.orhanobut.logger.DiskLogWriteReadStrategy
9-
import com.orhanobut.logger.CsvFormatStrategy
10-
import com.orhanobut.logger.Logger
116

127
object LogKit {
138

0 commit comments

Comments
 (0)