As we all know, the management of logs is a very important part of software system, must not neglect its importance. The complete log will play an important role in the maintenance of the system, like AX, the log is like a tool for analyzing the system, the tool is convenient, the system can be analyzed to achieve a multiplier effect. Developers must understand the value and significance of the log, and should not be ignored and despised.
Logcook is a very simple and practical Android Diary management tool. Logcook's Chinese translator is a log chef and you can think of it as a log foodie.
Characteristics
As a log management tool, its greatest feature is its simplicity and practicality , compared to the Android native log feature, which has several advantages:
- Supports the output of logs to a specified text file
- Support Capture App exception burst (Crash) and print output to specified file
- Support log switch for flexible control of output logs
- Support file save switch for flexible control of whether or not to save logs
Use tutorial one, add dependencies
Recommended Gradle References:
Add the following information in the outer build.gradle file:
allprojects { repositories { ... maven { url ‘https://jitpack.io‘ } } }
Add the following information to the Build.gradle file in the app folder:
dependencies { compile ‘com.github.whieenz:LogCook:v1.0‘}
Second, add File Write permission
To add the user permission in Manifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
Third, initialize
Create a new class that inherits from application, and you don't have to create a new one if you already have it in your project.
The override OnCreate () method initializes the Logcook in the OnCreate () method, with the following code:
@Override public void onCreate() { super.onCreate(); String logPath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/com.whieenz.logCook/log"; LogCook.getInstance() // 单例获取LogCook实例 .setLogPath(logPath) //设置日志保存路径 .setLogName("test.log") //设置日志文件名 .isOpen(true) //是否开启输出日志 .isSave(true) //是否保存日志 .initialize(); //完成吃初始化Crash监听 }
Add android:name= under the Application tab in Manifest.xml. MyApplication "Property, the code is as follows:
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:name=".MyApplication" android:theme="@style/AppTheme">
All right, here we go. Logcook configuration problems are all done, is it easy to find?
Iv. beginning of Use
Logcook's use of a very simple log format is fully compatible with Android native log printing methods. The use cases are as follows:
LogCook.v(TAG,"测试日志v");LogCook.i(TAG,"测试日志i");LogCook.d(TAG,"测试日志d");LogCook.w(TAG,"测试日志w");LogCook.e(TAG,"测试日志e");LogCook.log("测试日志log");
Five, matters needing attention
- The save path and file name of the log are set at the time of use, so be sure to note that the path and file name are valid
- Crash information is only captured and saved when the app is running, crash is saved in the path specified at initialization
Source Address
Https://github.com/whieenz/LogCook
If you like, please give a ☆ thank you!
Logcook a simple and practical Android Log management tool