Android log扩展

来源:互联网 发布:泰州网络推广 编辑:程序博客网 时间:2024/06/11 17:45

import android.util.Log;//Android 系统的log类

 

//send a DEBUG log message

Log.d(tag,msg);

//send an ERROR log message

Log.e(tag,msg);

//send a INFO log message

Log.i(tag,msg);

//send a VERBOSE log message

Log.v(tag,msg);

//send a WARN log message

Log.w(tag,msg);

 

如果应用到自己的项目中,会定义包装一个自己的log类

首先定义一个自己需要的log级别,比如说需要只打印error信息,或者打印出error与warn信息等等情况。

protected final static int LOG_LEVEL_0 = 0; // show nothing

protected final static int LOG_LEVEL_1 = 1; // show error info

protected final static int LOG_LEVEL_2 = 2; // show error and warn info

protected final static int LOG_LEVEL_3 = 3; // show error ,warn and info info

protected final static int LOG_LEVEL_4 = 4; //show all(error,warn,info,verbose)

 

//set your default LOG_LEVEL

procteted final static int LOG_LEVEL = LOG_LEVEL_4;

//set your output TAG

protected final static String TAG = "XXXX";

 

//package my own log function,it can print file name and line number of you log code excute

 

 

以上是在Java侧使用的log方式,如果在JNI与lib库(C++)侧使用log的话需要使用:

#include<android/log.h>

其中有定义:

 

使用方法:

__android_log_print(ANDROID_LOG_INFO, "TAG", "%s", "your msg");

 

方法总结,以上

原创粉丝点击