Use the LogPhoneUtil tool class to save APP running logs on Android phones, and android log tool class

Source: Internet
Author: User

Use the LogPhoneUtil tool class to save APP running logs on Android phones, and android log tool class

Recently, the company's tests have always proposed such a bug. Of course, they also blame their code for poor writing. Therefore, the test will always crash the app, and there is no log printing when they crash, when I come back to reproduce it, sometimes it's really hard to reproduce it, so it's troublesome. To facilitate viewing the cause of the bug in the mobile phone test, I wrote a small tool at home on weekends. I only needed to add the printing of the LogPhoneUtil class when printing the project's Log class, you can easily save logs on the app's mobile phone. A brief introduction is provided. You can view the source code on GIthub. Https://github.com/MuBob/PhoneLogUtil;

First, write the log file management class FileUtil to check whether sdcard exists and create log files under different directories.

Then, create an IOUtil class for reading and writing log files, which is used to operate file streams to write files.

Finally, create the LogUtil class and call the corresponding filter words of the class in the printing area.

When reading and writing files in the LogUtil class, you need to enable the Sub-thread to avoid interface freezing because it is not operated in the main thread, to enable the sub-thread, You need to lock the log file so that you can easily use this tool class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.