广告也精彩
目录

 

一:Log等级介绍

Android的Log等级通常有五类,按照日志级别由低到高分别是Verbose、Debug、Info、Warning、Error,其对应的log定义在system层。
  1. V   :  Verbose就是冗长啰嗦的。通常表达开发调试过程中的一些详细信息,用Log.v()输出,不过滤地输出所有调试信息。是最低级的Log可以不用管。

  1. D   :  Debug来表达调试信息。用Log.d()输出,能输出Debug、Info、Warning、Error级别的Log信息。

  1. I   :  Info来表达一些信息。用Log.i()输出,能输出Info、Warning、Error级别的Log信息。

  1. W   :  Warning表示警告,但不一定会马上出现错误,开发时有时用来表示特别注意的地方。用Log.w()输出,能输出Warning、Error级别的Log信息。

  1. E   :  Error表示出现错误,是最需要关注解决的。用Log.e()输出,能输出Error级别的Log信息。

注:Info、Warnning、Error等级的Log在普通调试中不随意滥用,存在发布版本中。在开发调试版本中,才会显示全部等级。
以上内容摘抄于《Android的Log等级

二:自定义log工具类

示例代码一

package com.biumall
.utils;

import android.util.Log;

public class LogUtils {

	// constant value
	public static final int LOG_LEVEL_V = 5;
	public static final int LOG_LEVEL_D = 4;
	public static final int LOG_LEVEL_I = 3;
	public static final int LOG_LEVEL_W = 2;
	public static final int LOG_LEVEL_E = 1;

	public static int log_level = LOG_LEVEL_V; // default log level

	public static String TAG = "www.91es.com"; //

	public static void v(String msg) {
		if (log_level >= LOG_LEVEL_V) {
			Log.d(TAG, msg);
		}
		return;
	}

	public static void v(String tag, String msg) {
		if (log_level >= LOG_LEVEL_V) {
			Log.d(tag, msg);
		}
		return;
	}

	public static void d(String msg) {
		if (log_level >= LOG_LEVEL_D) {
			Log.d(TAG, msg);
		}
		return;
	}

	public static void d(String tag, String msg) {
		if (log_level >= LOG_LEVEL_D) {
			Log.d(tag, msg);
		}
		return;
	}

	public static void i(String msg) {
		if (log_level >= LOG_LEVEL_I) {
			Log.d(TAG, msg);
		}
		return;
	}

	public static void i(String tag, String msg) {
		if (log_level >= LOG_LEVEL_I) {
			Log.d(tag, msg);
		}

		return;
	}

	public static void w(String msg) {
		if (log_level >= LOG_LEVEL_W) {
			Log.d(TAG, msg);
		}
		return;
	}

	public static void w(String tag, String msg) {
		if (log_level >= LOG_LEVEL_W) {
			Log.d(tag, msg);
		}

		return;
	}

	public static void e(String msg) {
		if (log_level >= LOG_LEVEL_E) {
			Log.d(TAG, msg);
		}
		return;
	}

	public static void e(String tag, String msg) {
		if (log_level >= LOG_LEVEL_E) {
			Log.d(tag, msg);
		}

		return;
	}
}

示例代码二

package com.biumall.utils;

import android.util.Log;

public class LogUtils {

	public static boolean isDebug = true; // default debug model true
	public static String TAG = "www.l25la.com";// default tag

	public static void d(String msg) {
		if (isDebug) {
			Log.d(TAG, msg);
		}
		return;
	}

	public static void d(String tag, String msg) {
		if (isDebug) {
			Log.d(tag, msg);
		}
		return;
	}

	public static void e(String msg) {
		if (isDebug) {
			Log.e(TAG, msg);
		}
		return;
	}

	public static void e(String tag, String msg) {
		if (isDebug) {
			Log.e(tag, msg);
		}
		return;
	}

	public static void v(String msg) {
		if (isDebug) {
			Log.v(TAG, msg);
		}
		return;
	}

	public static void v(String tag, String msg) {
		if (isDebug) {
			Log.v(tag, msg);
		}
		return;
	}

	public static void w(String msg) {
		if (isDebug) {
			Log.w(TAG, msg);
		}
		return;
	}

	public static void w(String tag, String msg) {
		if (isDebug) {
			Log.w(tag, msg);
		}
		return;
	}

	public static void i(String msg) {
		if (isDebug) {
			Log.i(TAG, msg);
		}
		return;
	}

	public static void i(String tag, String msg) {
		if (isDebug) {
			Log.i(tag, msg);
		}
		return;
	}
}

个人偏向于代码一,可以通过level调节日志的输出,当然代码示例二也用。

 历史上的今天

版权声明 1、 本站名称: 91易搜
2、 本站网址: 91es.com3xcn.com
3、 本站文章: 部分来源于网络,仅供站长学习和参考,若侵权请留言
广告也精彩

相关文章

广告也精彩

暂无评论

评论审核已启用。您的评论可能需要一段时间后才能被显示。

暂无评论...

网站升级中

公告

近期网站升级中,可能存在一些bug。欢迎反馈 https://www.91es.com/we.html

本站域名

本站域名 : 91es.com3xcn.com。本站邮箱 : 站长邮箱 i@oorr.cn,通知邮箱we@oorr.cn ,如有更新,请看公告 。