Skip to content

Commit 6b4ae64

Browse files
committed
see 05/19 log
1 parent f1e53c7 commit 6b4ae64

File tree

6 files changed

+199
-142
lines changed

6 files changed

+199
-142
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ public void onCreate() {
3737

3838
public static void initLog() {
3939
LogUtils.Builder builder = new LogUtils.Builder()
40-
.setLogSwitch(BuildConfig.DEBUG)// 设置log总开关,默认开
40+
.setLogSwitch(BuildConfig.DEBUG)// 设置log总开关,包括输出到控制台和文件,默认开
41+
.setConsoleSwitch(BuildConfig.DEBUG)// 设置是否输出到控制台开关,默认开
4142
.setGlobalTag(null)// 设置log全局标签,默认为空
4243
// 当全局标签不为空时,我们输出的log全部为该tag,
4344
// 为空时,如果传入的tag为空那就显示类名,否则显示tag
4445
.setLogHeadSwitch(true)// 设置log头信息开关,默认为开
4546
.setLog2FileSwitch(false)// 打印log时是否存到文件的开关,默认关
4647
.setDir("")// 当自定义路径为空时,写入应用的/cache/log/目录中
4748
.setBorderSwitch(true)// 输出日志是否带边框开关,默认开
48-
.setLogFilter(LogUtils.V);// log过滤器,和logcat过滤器同理,默认Verbose
49+
.setConsoleFilter(LogUtils.V)// log的控制台过滤器,和logcat过滤器同理,默认Verbose
50+
.setFileFilter(LogUtils.V);// log文件过滤器,和logcat过滤器同理,默认Verbose
4951
LogUtils.d(builder.toString());
5052
}
5153

app/src/main/java/com/blankj/androidutilcode/activity/LogActivity.java

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@ public class LogActivity extends BaseActivity {
2929

3030
private LogUtils.Builder mBuilder = new LogUtils.Builder();
3131

32-
private String dir = "";
33-
private String globalTag = "";
34-
private boolean head = true;
35-
private boolean file = false;
36-
private boolean border = true;
37-
private int filter = LogUtils.V;
38-
39-
private static final int UPDATE_TAG = 0x01;
40-
private static final int UPDATE_HEAD = 0x01 << 1;
41-
private static final int UPDATE_FILE = 0x01 << 2;
42-
private static final int UPDATE_DIR = 0x01 << 3;
43-
private static final int UPDATE_BORDER = 0x01 << 4;
44-
private static final int UPDATE_FILTER = 0x01 << 5;
32+
private String dir = "";
33+
private String globalTag = "";
34+
private boolean log = true;
35+
private boolean console = true;
36+
private boolean head = true;
37+
private boolean file = false;
38+
private boolean border = true;
39+
private int consoleFilter = LogUtils.V;
40+
private int fileFilter = LogUtils.V;
41+
42+
private static final int UPDATE_LOG = 0x01;
43+
private static final int UPDATE_CONSOLE = 0x01 << 1;
44+
private static final int UPDATE_TAG = 0x01 << 2;
45+
private static final int UPDATE_HEAD = 0x01 << 3;
46+
private static final int UPDATE_FILE = 0x01 << 4;
47+
private static final int UPDATE_DIR = 0x01 << 5;
48+
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;
4551

4652
private Runnable mRunnable = new Runnable() {
4753
@Override
@@ -79,12 +85,15 @@ public int bindLayout() {
7985

8086
@Override
8187
public void initView(Bundle savedInstanceState, View view) {
88+
findViewById(R.id.btn_toggle_log).setOnClickListener(this);
89+
findViewById(R.id.btn_toggle_console).setOnClickListener(this);
8290
findViewById(R.id.btn_toggle_tag).setOnClickListener(this);
8391
findViewById(R.id.btn_toggle_head).setOnClickListener(this);
8492
findViewById(R.id.btn_toggle_border).setOnClickListener(this);
8593
findViewById(R.id.btn_toggle_file).setOnClickListener(this);
8694
findViewById(R.id.btn_toggle_dir).setOnClickListener(this);
87-
findViewById(R.id.btn_toggle_filter).setOnClickListener(this);
95+
findViewById(R.id.btn_toggle_conole_filter).setOnClickListener(this);
96+
findViewById(R.id.btn_toggle_file_filter).setOnClickListener(this);
8897
findViewById(R.id.btn_log_no_tag).setOnClickListener(this);
8998
findViewById(R.id.btn_log_with_tag).setOnClickListener(this);
9099
findViewById(R.id.btn_log_in_new_thread).setOnClickListener(this);
@@ -106,6 +115,12 @@ public void doBusiness(Context context) {
106115
@Override
107116
public void onWidgetClick(View view) {
108117
switch (view.getId()) {
118+
case R.id.btn_toggle_log:
119+
updateAbout(UPDATE_LOG);
120+
break;
121+
case R.id.btn_toggle_console:
122+
updateAbout(UPDATE_CONSOLE);
123+
break;
109124
case R.id.btn_toggle_tag:
110125
updateAbout(UPDATE_TAG);
111126
break;
@@ -121,8 +136,11 @@ public void onWidgetClick(View view) {
121136
case R.id.btn_toggle_border:
122137
updateAbout(UPDATE_BORDER);
123138
break;
124-
case R.id.btn_toggle_filter:
125-
updateAbout(UPDATE_FILTER);
139+
case R.id.btn_toggle_conole_filter:
140+
updateAbout(UPDATE_CONSOLE_FILTER);
141+
break;
142+
case R.id.btn_toggle_file_filter:
143+
updateAbout(UPDATE_FILE_FILTER);
126144
break;
127145
case R.id.btn_log_no_tag:
128146
LogUtils.v("verbose");
@@ -164,23 +182,32 @@ public void onWidgetClick(View view) {
164182
LogUtils.d(longStr);
165183
break;
166184
case R.id.btn_log_file:
167-
for (int i = 0; i < 1000; i++) {
185+
for (int i = 0; i < 100; i++) {
168186
LogUtils.file("test0 log to file");
187+
LogUtils.file(LogUtils.I, "test0 log to file");
169188
}
170189
break;
171190
case R.id.btn_log_json:
172191
String json = "{\"tools\": [{ \"name\":\"css format\" , \"site\":\"http://tools.w3cschool.cn/code/css\" },{ \"name\":\"json format\" , \"site\":\"http://tools.w3cschool.cn/code/json\" },{ \"name\":\"pwd check\" , \"site\":\"http://tools.w3cschool.cn/password/my_password_safe\" }]}";
173192
LogUtils.json(json);
193+
LogUtils.json(LogUtils.I, json);
174194
break;
175195
case R.id.btn_log_xml:
176196
String xml = "<books><book><author>Jack Herrington</author><title>PHP Hacks</title><publisher>O'Reilly</publisher></book><book><author>Jack Herrington</author><title>Podcasting Hacks</title><publisher>O'Reilly</publisher></book></books>";
177197
LogUtils.xml(xml);
198+
LogUtils.xml(LogUtils.I, xml);
178199
break;
179200
}
180201
}
181202

182203
private void updateAbout(int args) {
183204
switch (args) {
205+
case UPDATE_LOG:
206+
log = !log;
207+
break;
208+
case UPDATE_CONSOLE:
209+
console = !console;
210+
break;
184211
case UPDATE_TAG:
185212
globalTag = globalTag.equals(TAG) ? "" : TAG;
186213
break;
@@ -202,16 +229,22 @@ private void updateAbout(int args) {
202229
case UPDATE_BORDER:
203230
border = !border;
204231
break;
205-
case UPDATE_FILTER:
206-
filter = filter == LogUtils.V ? LogUtils.W : LogUtils.V;
232+
case UPDATE_CONSOLE_FILTER:
233+
consoleFilter = consoleFilter == LogUtils.V ? LogUtils.W : LogUtils.V;
234+
break;
235+
case UPDATE_FILE_FILTER:
236+
fileFilter = fileFilter == LogUtils.V ? LogUtils.I : LogUtils.V;
207237
break;
208238
}
209-
mBuilder.setGlobalTag(globalTag)
239+
mBuilder.setLogSwitch(log)
240+
.setConsoleSwitch(console)
241+
.setGlobalTag(globalTag)
210242
.setLogHeadSwitch(head)
211243
.setLog2FileSwitch(file)
212244
.setDir(dir)
213245
.setBorderSwitch(border)
214-
.setLogFilter(filter);
246+
.setConsoleFilter(consoleFilter)
247+
.setFileFilter(fileFilter);
215248
tvAboutLog.setText(mBuilder.toString());
216249
}
217250

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717
android:layout_height="wrap_content"
1818
android:gravity="center"/>
1919

20+
<Button
21+
android:id="@+id/btn_toggle_log"
22+
style="@style/WideBtnStyle"
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content"
25+
android:text="@string/log_toggle_log"/>
26+
27+
<Button
28+
android:id="@+id/btn_toggle_console"
29+
style="@style/WideBtnStyle"
30+
android:layout_width="match_parent"
31+
android:layout_height="wrap_content"
32+
android:text="@string/log_toggle_console"/>
33+
2034
<Button
2135
android:id="@+id/btn_toggle_tag"
2236
style="@style/WideBtnStyle"
@@ -53,11 +67,18 @@
5367
android:text="@string/log_toggle_border"/>
5468

5569
<Button
56-
android:id="@+id/btn_toggle_filter"
70+
android:id="@+id/btn_toggle_conole_filter"
71+
style="@style/WideBtnStyle"
72+
android:layout_width="match_parent"
73+
android:layout_height="wrap_content"
74+
android:text="@string/log_toggle_console_filter"/>
75+
76+
<Button
77+
android:id="@+id/btn_toggle_file_filter"
5778
style="@style/WideBtnStyle"
5879
android:layout_width="match_parent"
5980
android:layout_height="wrap_content"
60-
android:text="@string/log_toggle_filter"/>
81+
android:text="@string/log_toggle_file_filter"/>
6182

6283
<Button
6384
android:id="@+id/btn_log_no_tag"

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
<string name="uninstall_successfully">Uninstall successfully</string>
4343
<string name="uninstall_unsuccessfully">Uninstall unsuccessfully</string>
4444
<string name="app_launch">Launch App</string>
45-
<string name="app_close">Close App</string>
46-
<string name="app_isDebug">Is Debug</string>
4745
<string name="app_get_details_settings">Get App Details Settings</string>
4846

4947

@@ -86,10 +84,13 @@
8684
<string name="keyboard_toggle_soft_input">Toggle Soft Input</string>
8785

8886
<!-- log -->
87+
<string name="log_toggle_log">Toggle Log</string>
88+
<string name="log_toggle_console">Toggle Console</string>
8989
<string name="log_toggle_tag">Toggle Tag</string>
9090
<string name="log_toggle_head">Toggle Head</string>
9191
<string name="log_toggle_border">Toggle Border</string>
92-
<string name="log_toggle_filter">Toggle Filter</string>
92+
<string name="log_toggle_console_filter">Toggle Console Filter</string>
93+
<string name="log_toggle_file_filter">Toggle File Filter</string>
9394
<string name="log_toggle_file">Toggle File</string>
9495
<string name="log_toggle_dir">Toggle Dir</string>
9596
<string name="log_with_no_tag">Log With No Tag</string>
@@ -109,7 +110,6 @@
109110
<string name="phone_send_sms_silent">Send SMS Silent</string>
110111

111112
<!--Process相关-->
112-
<string name="process_kill_background">Kill Background Process</string>
113113
<string name="process_kill_all_background">Kill All Background Processes</string>
114114

115115
<!--SnackBar相关工具类-->
@@ -125,7 +125,6 @@
125125
<string name="snackbar_short">Short Snackbar</string>
126126
<string name="snackbar_long">Long Snackbar</string>
127127
<string name="snackbar_indefinite">Indefinite Snackbar</string>
128-
<string name="snackbar_custom">Custom Snackbar</string>
129128
<string name="snackbar_click">Click</string>
130129

131130
<!--Toast相关-->

0 commit comments

Comments
 (0)