Skip to content

Commit a432242

Browse files
committed
新增英文版的文档和 Demo apk
1 parent 53945e3 commit a432242

29 files changed

+573
-106
lines changed

HelpDoc-en.md

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
# Table of Contents
2+
3+
* [Logcat Entry Configuration](#logcat-entry-configuration)
4+
5+
* [Logcat Activity Orientation Configuration](#logcat-activity-orientation-configuration)
6+
7+
* [Set Logcat Log Display Colors](#set-logcat-log-display-colors)
8+
9+
* [Set Logcat Default Filter Conditions](#set-logcat-default-filter-conditions)
10+
11+
* [Set Logcat Log Filter Rules](#set-logcat-log-filter-rules)
12+
13+
* [Show All Application Printed Logs](#show-all-application-printed-logs)
14+
15+
* [How to Use This Library in Production](#how-to-use-this-library-in-production)
16+
17+
* [What to Do If the Entry Cannot Be Displayed in Multi-Process Situations](#what-to-do-if-the-entry-cannot-be-displayed-in-multi-process-situations)
18+
19+
* [How to Disable Automatic Merging of Logs with the Same TAG](#how-to-disable-automatic-merging-of-logs-with-the-same-tag)
20+
21+
#### Logcat Entry Configuration
22+
23+
* The framework provides two default entry points:
24+
25+
* Notification bar entry
26+
27+
* Floating window entry
28+
29+
* The default rule for the entry: If the notification bar permission is granted, the notification bar entry will be used first; otherwise, the floating window entry will be displayed.
30+
31+
* How to modify the default rule? You can add the following configuration in the manifest file:
32+
33+
```xml
34+
<manifest>
35+
<application>
36+
<!-- Floating window entry -->
37+
<meta-data
38+
android:name="LogcatWindowEntrance"
39+
android:value="false" />
40+
<!-- Notification bar entry -->
41+
<meta-data
42+
android:name="LogcatNotifyEntrance"
43+
android:value="true" />
44+
</application>
45+
</manifest>
46+
```
47+
48+
#### Logcat Activity Orientation Configuration
49+
50+
* `LogcatActivity` follows the device screen orientation by default. If you need to fix it to portrait orientation, add the following configuration in your manifest file:
51+
52+
```xml
53+
<activity
54+
android:name="com.hjq.logcat.LogcatActivity"
55+
android:configChanges="orientation|screenSize|keyboardHidden"
56+
android:launchMode="singleInstance"
57+
android:screenOrientation="portrait"
58+
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
59+
tools:node="replace" />
60+
```
61+
62+
#### Set Logcat Log Display Colors
63+
64+
* Add your preferred color configuration in the project's `values/color.xml`, for example:
65+
66+
```xml
67+
<color name="logcat_level_verbose_color">#FFBBBBBB</color>
68+
<color name="logcat_level_debug_color">#FF33B5E5</color>
69+
<color name="logcat_level_info_color">#FF99CC00</color>
70+
<color name="logcat_level_warn_color">#FFFFBB33</color>
71+
<color name="logcat_level_error_color">#FFFF4444</color>
72+
<color name="logcat_level_other_color">#FFFFFFFF</color>
73+
```
74+
75+
#### Set Logcat Default Filter Conditions
76+
77+
* To modify the framework's default filter conditions, just add the following configuration in the manifest file:
78+
79+
```xml
80+
<manifest>
81+
<application>
82+
<!-- Default search keyword -->
83+
<meta-data
84+
android:name="LogcatDefaultSearchKey"
85+
android:value="MainActivity" />
86+
<!-- Default log level -->
87+
<meta-data
88+
android:name="LogcatDefaultLogLevel"
89+
android:value="E" />
90+
</application>
91+
</manifest>
92+
```
93+
94+
#### Set Logcat Log Filter Rules
95+
96+
* Add the log TAGs you want to filter in the project's `values/string.xml`, for example:
97+
98+
```xml
99+
<string-array name="logcat_filter_list" tools:ignore="ExtraTranslation">
100+
<item>ActivityThread</item>
101+
<item>InputMethodManager</item>
102+
<item>OpenGLRenderer</item>
103+
<item>VideoCapabilities</item>
104+
<item>ViewRootImpl</item>
105+
<item>Settings</item>
106+
<item>Looper</item>
107+
<item>TextView</item>
108+
<item>TypefaceUtils</item>
109+
<item>MultiDex</item>
110+
<item>AudioManager</item>
111+
<item>ConnectivityManager</item>
112+
<item>NetworkSecurityConfig</item>
113+
<item>HwPolicyFactory:</item>
114+
<item>HwWidgetFactory:</item>
115+
<item>HwApiCacheMangerEx</item>
116+
<item>HwWechatOptimizeImpl</item>
117+
<item>HwSplineOverScrollerExImpl</item>
118+
<item>HwAppInnerBoostImpl</item>
119+
<item>HwCustConnectivityManagerImpl</item>
120+
<item>HwApsImpl</item>
121+
<item>HwPhoneWindow</item>
122+
<item>HwAutofillHelper</item>
123+
<item>hwbr_engine_mainprocess</item>
124+
<item>hwbr_engine_hwbr_event</item>
125+
<item>hwbr_engine_PathUtils</item>
126+
<item>hwbr_engine_AwContents</item>
127+
<item>hwbr_engine_cr_IMM</item>
128+
<item>hwbr_engine_LibraryLoader</item>
129+
<item>hwbr_engine_BrowserStartup</item>
130+
<item>hwbr_engine_cr_WebContentsImpl</item>
131+
<item>CrashReport</item>
132+
<item>CrashReportInfo</item>
133+
<item>CrashReport-Native</item>
134+
<item>LeakCanary</item>
135+
<item>Timeline</item>
136+
<item>AssistStructure</item>
137+
<item>EgretLoader</item>
138+
<item>OverScrollerOptimization</item>
139+
<item>HiTouch_PressGestureDetector</item>
140+
<item>HiTouch_HiTouchSensor</item>
141+
<item>FLTAG_SFM</item>
142+
<item>FLTAG_FM</item>
143+
<item>libEGL</item>
144+
<item>AwareLog</item>
145+
<item>AwareBitmapCacher</item>
146+
<item>AwareAppScheduleManager</item>
147+
<item>FeatureFactory</item>
148+
<item>WebViewFactory</item>
149+
<item>ConfigStore</item>
150+
<item>mali_winsys</item>
151+
<item>ZrHung.AppEyeUiProbe</item>
152+
<item>chatty</item>
153+
<item>stylus</item>
154+
<item>libc</item>
155+
<item>chromium</item>
156+
<item>Perf</item>
157+
<item>FeatureParser</item>
158+
<item>Binder:intercep</item>
159+
<item>cr_LibraryLoader</item>
160+
<item>cr_BrowserStartup</item>
161+
<item>DecorView</item>
162+
<item>DecorView[]</item>
163+
<item>ForceDarkHelper</item>
164+
<item>skia</item>
165+
<item>AdrenoGLES-0</item>
166+
<item>ViewContentFactory</item>
167+
<item>MiuiFrameworkFactory</item>
168+
<item>MIUIInput</item>
169+
<item>cr_media</item>
170+
<item>cr_CachingUmaRecorder</item>
171+
<item>TetheringManager</item>
172+
<item>MiuiFreeDragHelper</item>
173+
<item>MiuiFreeDragImpl</item>
174+
<item>ContentProviderMonitor</item>
175+
<item>ContentCatcher</item>
176+
<item>ApplicationLoaders</item>
177+
<item>RenderInspector</item>
178+
</string-array>
179+
```
180+
181+
#### Show All Application Printed Logs
182+
183+
* First, note that an app itself cannot obtain logs from other apps.
184+
185+
* If you need this, it can be achieved by entering the following adb command on your computer:
186+
187+
```text
188+
// Grant the specified app permission to read logs. Replace com.hjq.logcat.demo with your package name.
189+
adb shell pm grant com.hjq.logcat.demo android.permission.READ_LOGS
190+
```
191+
192+
* Restart the app for it to take effect (some phones may automatically kill the process). Once authorized, the permission will remain unless the app is uninstalled.
193+
194+
* If the above command fails and you see the following message:
195+
196+
```text
197+
Exception occurred while executing 'grant':
198+
java.lang.SecurityException: grantRuntimePermission:
199+
Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS.
200+
```
201+
202+
* Then you need to enable the `USB debugging (Security settings)` option in Developer Options.
203+
204+
![](picture/en/usb_debugging_security_setting.jpg)
205+
206+
* If you still get the same message after enabling, try the following:
207+
208+
* Wait 5 minutes
209+
210+
* Replug your phone
211+
212+
* Check if `USB Installation` is enabled
213+
214+
* Re-enable `USB Debugging (Security)`
215+
216+
* Restart the cmd terminal
217+
218+
* Restart your phone and try again
219+
220+
* Try another phone
221+
222+
* The author recommends not enabling this feature unless necessary, as it will increase the amount and complexity of logs displayed by Logcat, making searching more difficult.
223+
224+
#### How to Use This Library in Production
225+
226+
* It is highly discouraged to use this library in production, as it is designed for debugging purposes. The author cannot guarantee its behavior in production. However, if you must do so, follow these steps:
227+
228+
* Step 1: Change the dependency from `debugImplementation` to `implementation`:
229+
230+
```groovy
231+
dependencies {
232+
debugImplementation 'com.github.getActivity:Logcat:x.x'
233+
}
234+
```
235+
236+
```groovy
237+
dependencies {
238+
implementation 'com.github.getActivity:Logcat:x.x'
239+
}
240+
```
241+
242+
* Step 2: Hide the Logcat entry points:
243+
244+
```xml
245+
<manifest>
246+
<application>
247+
<!-- Floating window entry -->
248+
<meta-data
249+
android:name="LogcatWindowEntrance"
250+
android:value="false" />
251+
<!-- Notification bar entry -->
252+
<meta-data
253+
android:name="LogcatNotifyEntrance"
254+
android:value="false" />
255+
</application>
256+
</manifest>
257+
```
258+
259+
* Step 3: Manually launch Logcat at the appropriate time:
260+
261+
```java
262+
try {
263+
Class<?> clazz = Class.forName("com.hjq.logcat.LogcatActivity");
264+
startActivity(new Intent(this, clazz));
265+
} catch (ClassNotFoundException e) {
266+
e.printStackTrace();
267+
}
268+
```
269+
270+
#### What to Do If the Entry Cannot Be Displayed in Multi-Process Situations
271+
272+
* This issue has been raised before [Logcat/issues/35](https://github.com/getActivity/Logcat/issues/35), but after verification, it cannot be fixed. This is because when a subprocess is started, the Application object is created again and the onCreate method is called again. However, the ContentProvider component is different and will not be created again, which causes a problem. The Logcat framework relies on ContentProvider as the initialization entry, but it will not be created again in the subprocess, nor will it be called. This is a fundamental limitation.
273+
274+
* However, there is a workaround: you can manually initialize the Logcat framework as follows:
275+
276+
* Step 1: Remove the Logcat framework initialization entry from the manifest file:
277+
278+
```xml
279+
<?xml version="1.0" encoding="utf-8"?>
280+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
281+
xmlns:tools="http://schemas.android.com/tools"
282+
package="com.xxx.xxx">
283+
<application>
284+
<provider
285+
android:name="com.hjq.logcat.LogcatProvider"
286+
tools:node="remove" />
287+
</application>
288+
</manifest>
289+
```
290+
291+
* Step 2: Manually initialize the Logcat framework in Application.onCreate:
292+
293+
```java
294+
public final class XxxApplication extends Application {
295+
@Override
296+
public void onCreate() {
297+
super.onCreate();
298+
try {
299+
Class<?> logcatProviderClass = Class.forName("com.hjq.logcat.LogcatProvider");
300+
Object logcatProvider = logcatProviderClass.newInstance();
301+
Method attachInfoMethod = logcatProviderClass.getMethod("attachInfo", Context.class, ProviderInfo.class);
302+
attachInfoMethod.setAccessible(true);
303+
attachInfoMethod.invoke(logcatProvider, this, null);
304+
} catch (Exception e) {
305+
e.printStackTrace();
306+
}
307+
}
308+
}
309+
```
310+
311+
#### How to Disable Automatic Merging of Logs with the Same TAG
312+
313+
* When two or more logs with the same TAG are found, and no new TAG logs are inserted in between, the framework will automatically merge them for better display. If you do not need this feature, add the following configuration in the manifest file:
314+
315+
```xml
316+
<manifest>
317+
<application>
318+
<!-- Log merging (enabled by default) -->
319+
<meta-data
320+
android:name="LogcatAutoMergePrint"
321+
android:value="false" />
322+
</application>
323+
</manifest>
324+
```

HelpDoc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ java.lang.SecurityException: grantRuntimePermission:
209209
Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS.
210210
```
211211

212-
* 则需要前往开发者选项中开启 `USB 调试(安全` 的设置选项
212+
* 则需要前往开发者选项中开启 `USB 调试(安全设置` 的设置选项
213213

214-
![](picture/usb_debugging_security_setting.jpg)
214+
![](picture/zh/usb_debugging_security_setting.jpg)
215215

216216
* 开启之后,如果还是一样的提示,证明没有生效,可以尝试以下操作
217217

0 commit comments

Comments
 (0)