Skip to content

Commit 87a39a6

Browse files
committed
see 04/03 log
1 parent ace742f commit 87a39a6

File tree

12 files changed

+86
-41
lines changed

12 files changed

+86
-41
lines changed

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.6-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.7-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If this ptoject helps you a lot, and you would like to support this ptoject's fu
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.6-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.7-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656
// LeakCanary
5757
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
5858
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
59-
// implementation 'com.blankj:utilcode:1.13.6'
59+
// implementation 'com.blankj:utilcode:1.13.7'
6060
}
6161

6262

app/src/main/java/com/blankj/androidutilcode/UtilsApp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ public void initLog() {
6262
.setDir("")// 当自定义路径为空时,写入应用的/cache/log/目录中
6363
.setFilePrefix("")// 当文件前缀为空时,默认为"util",即写入文件为"util-MM-dd.txt"
6464
.setBorderSwitch(true)// 输出日志是否带边框开关,默认开
65+
.setSingleTagSwitch(true)// 一条日志仅输出一条,默认开,为美化 AS 3.1 的 Logcat
6566
.setConsoleFilter(LogUtils.V)// log 的控制台过滤器,和 logcat 过滤器同理,默认 Verbose
6667
.setFileFilter(LogUtils.V)// log 文件过滤器,和 logcat 过滤器同理,默认 Verbose
67-
.setStackDeep(10);// log 栈深度,默认为 1
68+
.setStackDeep(1);// log 栈深度,默认为 1
6869
new Thread(new Runnable() {
6970
@Override
7071
public void run() {

app/src/main/java/com/blankj/androidutilcode/feature/core/log/LogActivity.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class LogActivity extends BaseBackActivity {
3636
private boolean head = true;
3737
private boolean file = false;
3838
private boolean border = true;
39+
private boolean single = true;
3940
private int consoleFilter = LogUtils.V;
4041
private int fileFilter = LogUtils.V;
4142

@@ -46,8 +47,9 @@ public class LogActivity extends BaseBackActivity {
4647
private static final int UPDATE_FILE = 0x01 << 4;
4748
private static final int UPDATE_DIR = 0x01 << 5;
4849
private static final int UPDATE_BORDER = 0x01 << 6;
49-
private static final int UPDATE_CONSOLE_FILTER = 0x01 << 7;
50-
private static final int UPDATE_FILE_FILTER = 0x01 << 8;
50+
private static final int UPDATE_SINGLE = 0x01 << 7;
51+
private static final int UPDATE_CONSOLE_FILTER = 0x01 << 8;
52+
private static final int UPDATE_FILE_FILTER = 0x01 << 9;
5153

5254
private Runnable mRunnable = new Runnable() {
5355
@Override
@@ -98,6 +100,7 @@ public void initView(Bundle savedInstanceState, View view) {
98100
findViewById(R.id.btn_toggle_tag).setOnClickListener(this);
99101
findViewById(R.id.btn_toggle_head).setOnClickListener(this);
100102
findViewById(R.id.btn_toggle_border).setOnClickListener(this);
103+
findViewById(R.id.btn_toggle_single).setOnClickListener(this);
101104
findViewById(R.id.btn_toggle_file).setOnClickListener(this);
102105
findViewById(R.id.btn_toggle_dir).setOnClickListener(this);
103106
findViewById(R.id.btn_toggle_conole_filter).setOnClickListener(this);
@@ -143,6 +146,9 @@ public void onWidgetClick(View view) {
143146
case R.id.btn_toggle_border:
144147
updateConfig(UPDATE_BORDER);
145148
break;
149+
case R.id.btn_toggle_single:
150+
updateConfig(UPDATE_SINGLE);
151+
break;
146152
case R.id.btn_toggle_conole_filter:
147153
updateConfig(UPDATE_CONSOLE_FILTER);
148154
break;
@@ -242,6 +248,9 @@ private void updateConfig(int args) {
242248
case UPDATE_BORDER:
243249
border = !border;
244250
break;
251+
case UPDATE_SINGLE:
252+
single = !single;
253+
break;
245254
case UPDATE_CONSOLE_FILTER:
246255
consoleFilter = consoleFilter == LogUtils.V ? LogUtils.W : LogUtils.V;
247256
break;
@@ -256,6 +265,7 @@ private void updateConfig(int args) {
256265
.setLog2FileSwitch(file)
257266
.setDir(dir)
258267
.setBorderSwitch(border)
268+
.setSingleTagSwitch(single)
259269
.setConsoleFilter(consoleFilter)
260270
.setFileFilter(fileFilter);
261271
tvAboutLog.setText(mConfig.toString());

app/src/main/res_core/layout/activity_log.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
android:layout_height="wrap_content"
6363
android:text="@string/log_toggle_border" />
6464

65+
<Button
66+
android:id="@+id/btn_toggle_single"
67+
style="@style/WideBtnStyle"
68+
android:layout_width="match_parent"
69+
android:layout_height="wrap_content"
70+
android:text="@string/log_toggle_single" />
71+
6572
<Button
6673
android:id="@+id/btn_toggle_conole_filter"
6774
style="@style/WideBtnStyle"

app/src/main/res_core/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
<string name="log_toggle_tag">Toggle Tag</string>
177177
<string name="log_toggle_head">Toggle Head</string>
178178
<string name="log_toggle_border">Toggle Border</string>
179+
<string name="log_toggle_single">Toggle Single</string>
179180
<string name="log_toggle_console_filter">Toggle Console Filter</string>
180181
<string name="log_toggle_file_filter">Toggle File Filter</string>
181182
<string name="log_toggle_file">Toggle File</string>

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ ext {
3333
min_sdk_version = 14
3434
target_sdk_version = 27
3535

36-
version_code = 1_013_006
37-
version_name = '1.13.6'// E.g 1.9.72 => 1,009,072
36+
version_code = 1_013_007
37+
version_name = '1.13.7'// E.g 1.9.72 => 1,009,072
3838

3939
// App dependencies
4040
support_version = '27.0.2'

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 18/04/03 修复 LogUtils 在 Android Studio 3.1 版本日志丑陋的问题,发布 1.13.7 版本
12
* 18/03/29 兼容 Utils 的初始化传入 application,发布 1.13.6 版本
23
* 18/03/20 修复 PermissionUtils 子进程的问题,发布 1.13.5 版本
34
* 18/03/16 新增 gradle 插件来格式化 README

utilcode/README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
compile 'com.blankj:utilcode:1.13.6'
5+
compile 'com.blankj:utilcode:1.13.7'
66
```
77

88

utilcode/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
compile 'com.blankj:utilcode:1.13.6'
5+
compile 'com.blankj:utilcode:1.13.7'
66
```
77

88

utilcode/src/main/java/com/blankj/utilcode/util/LogUtils.java

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ public final class LogUtils {
7777
private static final String TOP_BORDER = TOP_CORNER + SIDE_DIVIDER + SIDE_DIVIDER;
7878
private static final String MIDDLE_BORDER = MIDDLE_CORNER + MIDDLE_DIVIDER + MIDDLE_DIVIDER;
7979
private static final String BOTTOM_BORDER = BOTTOM_CORNER + SIDE_DIVIDER + SIDE_DIVIDER;
80-
private static final int MAX_LEN = 4000;
80+
private static final int MAX_LEN = 3000;
8181
@SuppressLint("SimpleDateFormat")
8282
private static final Format FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS ");
8383
private static final String NOTHING = "log nothing";
8484
private static final String NULL = "null";
8585
private static final String ARGS = "args";
86+
private static final String PLACEHOLDER = " ";
8687
private static final Config CONFIG = new Config();
8788

8889
private static ExecutorService sExecutor;
@@ -96,10 +97,12 @@ public final class LogUtils {
9697
private static boolean sLogHeadSwitch = true; // The head's switch of log.
9798
private static boolean sLog2FileSwitch = false; // The file's switch of log.
9899
private static boolean sLogBorderSwitch = true; // The border's switch of log.
100+
private static boolean sSingleTagSwitch = true; // The single tag of log.
99101
private static int sConsoleFilter = V; // The console's filter of log.
100102
private static int sFileFilter = V; // The file's filter of log.
101103
private static int sStackDeep = 1; // The stack's deep of log.
102104

105+
103106
private LogUtils() {
104107
throw new UnsupportedOperationException("u can't instantiate me...");
105108
}
@@ -344,31 +347,32 @@ private static void print2Console(final int type,
344347
final String tag,
345348
final String[] head,
346349
final String msg) {
347-
StringBuilder sb = new StringBuilder();
348-
sb.append(" ").append(LINE_SEP);
349-
if (sLogBorderSwitch) {
350-
sb.append(TOP_BORDER).append(LINE_SEP);
351-
for (String aHead : head) {
352-
sb.append(LEFT_BORDER).append(aHead).append(LINE_SEP);
353-
}
354-
sb.append(MIDDLE_BORDER).append(LINE_SEP);
355-
for (String line : msg.split(LINE_SEP)) {
356-
sb.append(LEFT_BORDER).append(line).append(LINE_SEP);
350+
if (sSingleTagSwitch) {
351+
StringBuilder sb = new StringBuilder();
352+
sb.append(PLACEHOLDER).append(LINE_SEP);
353+
if (sLogBorderSwitch) {
354+
sb.append(TOP_BORDER).append(LINE_SEP);
355+
for (String aHead : head) {
356+
sb.append(LEFT_BORDER).append(aHead).append(LINE_SEP);
357+
}
358+
sb.append(MIDDLE_BORDER).append(LINE_SEP);
359+
for (String line : msg.split(LINE_SEP)) {
360+
sb.append(LEFT_BORDER).append(line).append(LINE_SEP);
361+
}
362+
sb.append(BOTTOM_BORDER);
363+
} else {
364+
for (String aHead : head) {
365+
sb.append(aHead).append(LINE_SEP);
366+
}
367+
sb.append(msg);
357368
}
358-
sb.append(BOTTOM_BORDER);
369+
printMsgSingleTag(type, tag, sb.toString());
359370
} else {
360-
for (String aHead : head) {
361-
sb.append(aHead).append(LINE_SEP);
362-
}
363-
sb.append(msg);
371+
printBorder(type, tag, true);
372+
printHead(type, tag, head);
373+
printMsg(type, tag, msg);
374+
printBorder(type, tag, false);
364375
}
365-
366-
printMsg1(type, tag, sb.toString());
367-
//
368-
// printBorder(type, tag, true);
369-
// printHead(type, tag, head);
370-
// printMsg(type, tag, msg);
371-
// printBorder(type, tag, false);
372376
}
373377

374378
private static void printBorder(final int type, final String tag, boolean isTop) {
@@ -403,17 +407,32 @@ private static void printMsg(final int type, final String tag, final String msg)
403407
}
404408
}
405409

406-
private static void printMsg1(final int type, final String tag, final String msg) {
410+
private static void printMsgSingleTag(final int type, final String tag, final String msg) {
407411
int len = msg.length();
408412
int countOfSub = len / MAX_LEN;
409413
if (countOfSub > 0) {
410-
int index = 0;
411-
for (int i = 0; i < countOfSub; i++) {
412-
Log.println(type, tag, msg.substring(index, index + MAX_LEN));
413-
index += MAX_LEN;
414-
}
415-
if (index != len) {
416-
Log.println(type, tag, msg.substring(index, len));
414+
if (sLogBorderSwitch) {
415+
Log.println(type, tag, msg.substring(0, MAX_LEN) + LINE_SEP + BOTTOM_BORDER);
416+
int index = MAX_LEN;
417+
for (int i = 1; i < countOfSub; i++) {
418+
Log.println(type, tag, PLACEHOLDER + LINE_SEP + TOP_BORDER + LINE_SEP
419+
+ LEFT_BORDER + msg.substring(index, index + MAX_LEN)
420+
+ LINE_SEP + BOTTOM_BORDER);
421+
index += MAX_LEN;
422+
}
423+
if (index != len) {
424+
Log.println(type, tag, PLACEHOLDER + LINE_SEP + TOP_BORDER + LINE_SEP
425+
+ LEFT_BORDER + msg.substring(index, len));
426+
}
427+
} else {
428+
int index = 0;
429+
for (int i = 0; i < countOfSub; i++) {
430+
Log.println(type, tag, msg.substring(index, index + MAX_LEN));
431+
index += MAX_LEN;
432+
}
433+
if (index != len) {
434+
Log.println(type, tag, msg.substring(index, len));
435+
}
417436
}
418437
} else {
419438
Log.println(type, tag, msg);
@@ -629,6 +648,11 @@ public Config setBorderSwitch(final boolean borderSwitch) {
629648
return this;
630649
}
631650

651+
public Config setSingleTagSwitch(final boolean singleTagSwitch) {
652+
sSingleTagSwitch = singleTagSwitch;
653+
return this;
654+
}
655+
632656
public Config setConsoleFilter(@TYPE final int consoleFilter) {
633657
sConsoleFilter = consoleFilter;
634658
return this;
@@ -654,6 +678,7 @@ public String toString() {
654678
+ LINE_SEP + "dir: " + (sDir == null ? sDefaultDir : sDir)
655679
+ LINE_SEP + "filePrefix: " + sFilePrefix
656680
+ LINE_SEP + "border: " + sLogBorderSwitch
681+
+ LINE_SEP + "singleTag: " + sSingleTagSwitch
657682
+ LINE_SEP + "consoleFilter: " + T[sConsoleFilter - V]
658683
+ LINE_SEP + "fileFilter: " + T[sFileFilter - V]
659684
+ LINE_SEP + "stackDeep: " + sStackDeep;

0 commit comments

Comments
 (0)