Logcook a simple and practical Android Log management tool

Source: Internet
Author: User

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:

    1. Supports the output of logs to a specified text file
    2. Support Capture App exception burst (Crash) and print output to specified file
    3. Support log switch for flexible control of output logs
    4. 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
    1. 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
    2. 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

Related Article

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.