好用的log打印类
package com.huawei.network.ott.weixin.util;
import android.util.Log;
public final class DebugLog {
/**
* 描述级别的日志标识,该级别为日志最低级别,发布时将关闭
*/
public static final int VERBOSE = 0;
/**
* 调试级别的日志标识,主要用于打印调试信息,发布时将关闭
*/
public static final int DEBUG = 1;
/**
* 信息级别的日志标识,主要用于打印数据,属性等信息,发布时将关闭
*/
public static final int INFO = 2;
/**
* 警告级别的日志标识,主要用于打印警告,发布时不关闭
*/
public static final int WARN = 3;
/**
* 错误级别的日志标识,主要用于打印错误,发布时不关闭
*/
public static final int ERROR = 4;
private static boolean isPrintLog = true;
private static int logLevel = VERBOSE;
/**
* 是否打印日志
*
* @return
*/
public static boolean isPrintLog() {
return isPrintLog;
}
/**
* 设置是否打印日志
*
* @param isPrintLog
* 如果设置为true,则打印日志,否则将不打印日志
*/
public static void setPrintLog(boolean isPrintLog) {
DebugLog.isPrintLog = isPrintLog;
}
/**
* 获取当前日志的打印最低Level
*
* @return
*/
public static int getLogLevel() {
return logLevel;
}
/**
* 设置当前日志的打印最低Level
*
* @param logLevel
*/
public static void setLogLevel(int logLevel) {
DebugLog.logLevel = logLevel;
}
/**
* 打印一个 {@link #VERBOSE} 日志信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
*/
public static int v(String tag, String msg) {
if (isPrintLog && VERBOSE >= logLevel) {
return Log.v(tag, msg);
} else {
return -1;
}
}
/**
* 打印一个 {@link #VERBOSE} 日志信息并打印异常信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
* @param tr
* An exception to log
*/
public static int v(String tag, String msg, Throwable tr) {
if (isPrintLog && VERBOSE >= logLevel) {
return Log.v(tag, msg, tr);
} else {
return -1;
}
}
/**
* 打印一个 {@link #DEBUG} 日志信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
*/
public static int d(String tag, String msg) {
if (isPrintLog && DEBUG >= logLevel) {
return Log.d(tag, msg);
} else {
return -1;
}
}
/**
* 打印一个 {@link #DEBUG} 日志信息并打印异常信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
* @param tr
* An exception to log
*/
public static int d(String tag, String msg, Throwable tr) {
if (isPrintLog && DEBUG >= logLevel) {
return Log.d(tag, msg, tr);
} else {
return -1;
}
}
/**
* 打印一个 {@link #INFO} 日志信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
*/
public static int i(String tag, String msg) {
if (isPrintLog && INFO >= logLevel) {
return Log.i(tag, msg);
} else {
return -1;
}
}
/**
* 打印一个 {@link #INFO} 日志信息并打印异常信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
* @param tr
* An exception to log
*/
public static int i(String tag, String msg, Throwable tr) {
if (isPrintLog && INFO >= logLevel) {
return Log.i(tag, msg, tr);
} else {
return -1;
}
}
/**
* 打印一个 {@link #WARN} 日志信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
*/
public static int w(String tag, String msg) {
if (isPrintLog && WARN >= logLevel) {
return Log.w(tag, msg);
} else {
return -1;
}
}
/**
* 打印一个 {@link #WARN} 异常信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
*/
public static int w(String tag, Throwable tr) {
if (isPrintLog && WARN >= logLevel) {
return Log.w(tag, tr);
} else {
return -1;
}
}
/**
* 打印一个 {@link #WARN} 日志信息并打印异常信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
* @param tr
* An exception to log
*/
public static int w(String tag, String msg, Throwable tr) {
if (isPrintLog && WARN >= logLevel) {
return Log.w(tag, msg, tr);
} else {
return -1;
}
}
/**
* 打印一个 {@link #ERROR} 日志信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
*/
public static int e(String tag, String msg) {
if (isPrintLog && ERROR >= logLevel) {
return Log.e(tag, msg);
} else {
return -1;
}
}
/**
* 打印一个 {@link #ERROR} 日志信息并打印异常信息。
*
* @param tag
* Used to identify the source of a log message. It usually
* identifies the class or activity where the log call occurs.
* @param msg
* The message you would like logged.
* @param tr
* An exception to log
*/
public static int e(String tag, String msg, Throwable tr) {
if (isPrintLog && ERROR >= logLevel) {
return Log.e(tag, msg, tr);
} else {
return -1;
}
}
}
好用的log打印类的更多相关文章
- python 以单例模式封装logging相关api实现日志打印类
python 以单例模式封装logging相关api实现日志打印类 by:授客QQ:1033553122 测试环境: Python版本:Python 2.7 实现功能: 支持自由配置,如下lo ...
- Android日志打印类LogUtils,能够定位到类名,方法名以及出现错误的行数并保存日志文件
Android日志打印类LogUtils,能够定位到类名,方法名以及出现错误的行数并保存日志文件 在开发中,我们常常用打印log的方式来调试我们的应用.在Java中我们常常使用方法System.out ...
- tiny4412 串口驱动分析七 --- log打印的几个阶段之内核启动阶段(earlyprintk)
作者:彭东林 邮箱:pengdonglin137@163.com 开发板:tiny4412ADK+S700 4GB Flash 主机:Wind7 64位 虚拟机:Vmware+Ubuntu12_04 ...
- Android4_学会使用Log打印
一.Log介绍: Android中的日志工具类是Log(android.util.Log),这个类中提供了如下5个方法来供我们打印日志. Log.v() .用于打印那些最为琐碎的.意义最小的日志信息. ...
- JS高级群的日常!写一个从10到0的倒计时,用console.log打印,不可以用 setInterval!本来说好的研究avalonJS最后演变成了看着大神在那边互相比拼实力。。
JS高级群的日常!写一个从10到0的倒计时,用console.log打印,不可以用 setInterval!本来说好的研究avalonJS最后演变成了看着大神在那边互相比拼实力.. 小森执行一 ...
- [asp.net]c# winform打印类
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using ...
- -XX:-PrintClassHistogram 按下Ctrl+Break后,打印类的信息
-XX:+PrintClassHistogram –按下Ctrl+Break后,打印类的信息: num #instances #bytes class name ------ ...
- 关于Debug下的Log打印问题
在项目中为了调试经常会用到Log打印,比如打印当前方法__func__, 对象,地址等等,所以项目最后每次运行调试控制台满满的都是打印日志,到release发布的时候,显然不太合适,这里其实可以用一个 ...
- javascript篇-console.log()打印object却显示为字符串[object object]
console.log打印对象遇到的一个问题,如下截图 打印结果与预期不符,原因是因为字符串‘a’和对象object拼接在一起,拼成了一个字符串
随机推荐
- MyBatis-Spring整合之方式2
提前叨叨:此方法优化了上一个方式的事务支持,同时简化了一个bean的配置 1.在方式1的基础上修改UserDaoImp文件,改用使用继承SqlSessionDaoSupport的方式.代码如下: pu ...
- JS高级---实例对象和构造函数之间的关系
实例对象和构造函数之间的关系: 1. 实例对象是通过构造函数来创建的---创建的过程叫实例化 2. 如何判断对象是不是这个数据类型? 1) 通过构造器的方式 实例对象.构造器==构造函数 ...
- mapreduce课上实验
今天我们课上做了一个关于数据清洗的实验,具体实验内容如下: 1.数据清洗:按照进行数据清洗,并将清洗后的数据导入hive数据库中: 2.数据处理: ·统计最受欢迎的视频/文章的Top10访问次数 (v ...
- JAVA(5)之关于main函数的默认放置位置
Eclipse默认主程序入口 Public class 的main函数 package com.study; public class Test { public static void main(S ...
- tkinter+pickle+python的一个登录界面设计
1.代码: #导出模块 import tkinter as tk from tkinter import messagebox import pickle #定义登录的窗口.标题.大小和位置 wind ...
- MySQL双机热备环境搭建
一. 前期准备 准备两台服务器(电脑),接入到同一局域网中,能够使双方可以ping通: 安装MySQL数据库,具体安装方法网上很全面,但是安装的版本需保持一致: 服务器IP地址设置. l A服 ...
- cascadia-code 程序员友好字体
下载地址:https://github.com/microsoft/cascadia-code/releases/download/v1911.21/Cascadia.ttf 下载后右键点击下载的文件 ...
- JavaSE复习~运算符与表达式
运算符 运算符:进行特定操作的符号 表达式:用运算符进行操作的式子 算术运算符 首先是加减乘除:+.-.*./还有取余:% 整数进行算术操作得到的还是整数,例如整数使用 / 得到的是整数(商的整数部分 ...
- hadoop集群启动报错: java.io.IOException: Incompatible clusterIDs
java.io.IOException: Incompatible clusterIDs in /export/hadoop-2.7.5/hadoopDatas/datanodeDatas2: nam ...
- Kubernetes的pod控制器及ReplicaSet控制器类型的pod的定义
为什么需要Pod Kubernetes项目之所以这么做的原因: 因为Kubernetes是谷歌公司基于Borg项目做出来的,谷歌工程师发现,他们部署的应用往往存在这进程与进程组的关系.具体说呢,就是这 ...