手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法
android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法
摘要:管理log一般有两种方法,博主推荐大家使用下面的第一种方法:第一种方法:第一步:定义一个logTools工具类,相信你能够看懂的,谁的log...

管理log一般有两种方法,博主推荐大家使用下面的第一种方法:

第一种方法:

第一步:定义一个logTools工具类,相信你能够看懂的,谁的log,可以用谁的名字做方法名,如logli,这就是工程师li打印的日志

复制代码 代码如下:

import android.util.Log;

public class LogTools {

public static boolean isShow = true;//上线模式

//public static boolean isShow = false;//开发模式

//ye工程师打出来的log

public static void logYe(String msg){

if(isShow){

Log.i("Ye", msg);

}

}

//li工程师打出来的log

public static void logli(String msg){

if(isShow){

Log.i("lili", msg);

}

}

}

第二步:在程序中应用的方式是:

复制代码 代码如下:

LogTools.logYe("onTouchEvent-----"+event.getAction());

android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法1

第二种方法:

在开发中经常要打印log,但是在我们发布项目的时候是不能打印。为了方便操作log我们需要自己定义个log类然后在开发阶段将下面LOG_LEVEL 设置为6这样所有的log都能显示,在发布的时候我们将LOG_LEVEL 设置为0.这样log就非常方便管理了

复制代码 代码如下:

public class Logger {

public static int LOG_LEVEL = 0;

public static int ERROR = 1;

public static int WARN = 2;

public static int INFO = 3;

public static int DEBUG = 4;

public static int VERBOS = 5;

public static void e(String tag,String msg){

if(LOG_LEVEL>ERROR)

Log.e(tag, msg);

}

public static void w(String tag,String msg){

if(LOG_LEVEL>WARN)

Log.w(tag, msg);

}

public static void i(String tag,String msg){

if(LOG_LEVEL>INFO)

Log.i(tag, msg);

}

public static void d(String tag,String msg){

if(LOG_LEVEL>DEBUG)

Log.d(tag, msg);

}

public static void v(String tag,String msg){

if(LOG_LEVEL>VERBOS)

Log.v(tag, msg);

}

}

【android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法】相关文章:

android 选项卡(TabHost)如何放置在屏幕的底部

Android 在其他线程中更新UI线程的解决方法

android帮助文档打开慢的三种解决方法

android平台的左右上下都能滚动的效果

Android自定义Style实现方法

android 引导界面的实现方法

android全屏去掉title栏的多种实现方法

Android 中对于图片的内存优化方法

android中ListView数据刷新时的同步方法

android UI进阶之android中隐藏的layout 抽屉的使用方法

精品推荐
分类导航