Log service functions are divided into two modules: logcat logs and logs buried point.
Log Type |
definition |
Feature |
effect |
logcat log |
Each app to print the log Log |
Full, but the key information is not obvious |
Analysis of the current network for positioning problem |
Buried log |
Formatting log |
Structured format / outstanding information / management platform can be used with statistics |
1. Analysis of product operations for user data 2. Locate the current network problems |
First, demand
the whole frame
logcat log generation and uploading scene
Timing diagram
Buried log
difficulty:
1. Log Process Management
Instructions executed in the process: logcat -v time | egrep -i "abcd"
2. Blocking output log reads the log process
buffRead = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = buffRead.readLine()) != null) {}
Here caching using StringBuffer, it is thread safe.
3. log output to a file and the encryption process
Read each line of the log will be spliced into the cache, write to the file after a certain number.
It can also be a time of polling trigger write to a file. (There will be multi-threading issues)
Write files using: FileOutputStream
Compression and encryption: gZip using the first compression, and then performing an exclusive OR encryption, there is a certain risk of the secret key may be stored in the code.
4. logcat file upload
Since the individual files are small files, required to support HTTP, so simply put through an interface file request to the cloud.
5. Buried log storage and upload management
Buried sdk with a separate management.