Use the logphoneutil tool class to save the app running log on the Android phone

Recently, the company's tests always put forward such and such bugs. Of course, they blame their bad code, so the tests always crash the app. When they crash, they haven't printed the log, and it's really hard to reproduce when they come back. Therefore, the trouble comes. In order to easily check the cause of the bug of the test mobile phone, I wrote a gadget at home at the weekend. As long as I add the printing of logphoneutil class when printing in the log class of the project, I can easily save the log on the mobile phone running the app. Briefly introduce the idea. The source code is on GitHub. You can also view it yourself. https://github.com/MuBob/PhoneLogUtil ;

First, write the log file management class fileutil to detect whether the sdcard exists, so as to create log files in different directories.

Then create the ioutil class for reading and writing log files, which is used to operate the file stream for file writing.

Finally, create a logutil class and call the corresponding filter words of this class at the printing place.

The key to the three simple steps is that when reading and writing files in the logutil class, in order not to operate in the main thread and cause interface jamming, you need to start the sub thread. If you start the sub thread, you need to lock the log file, so you can easily use this tool class.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>