经常使用Log日志打印输出
/**
* log刊物
* @author Jenly
*
*/
public class LogUtils { public static final String TAG = "Jenly"; private static final String COLON = ":"; private static final String ARROW = "->"; /** 是否显示Log日志 */
private static boolean isShowLog = true; /** Log日志优先权 */
private static int priority = 1; /**
* Priority constant for the println method;use System.out.println
*/
public static final int PRINTLN = 1; /**
* Priority constant for the println method; use Log.v.
*/
public static final int VERBOSE = 2; /**
* Priority constant for the println method; use Log.d.
*/
public static final int DEBUG = 3; /**
* Priority constant for the println method; use Log.i.
*/
public static final int INFO = 4; /**
* Priority constant for the println method; use Log.w.
*/
public static final int WARN = 5; /**
* Priority constant for the println method; use Log.e.
*/
public static final int ERROR = 6; /**
* Priority constant for the println method.use Log.wtf.
*/
public static final int ASSERT = 7; public static void setShowLog(boolean isShowLog){ LogUtils.isShowLog = isShowLog;
} public static boolean isShowLog(){ return isShowLog;
} public static int getPriority() { return priority;
} public static void setPriority(int priority) { LogUtils.priority = priority;
} //-----------------------------------Log.v /**
* Log.v
* @param e
*/
public static void v(Throwable e) {
if (isShowLog && priority <= VERBOSE)
v(TAG,e);
} public static void v(String tag,Throwable e) {
if (isShowLog && priority <= VERBOSE)
for(int i=0;i<e.getStackTrace().length;i++)
Log.v(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(e.getMessage())
.toString());
} public static void v(Throwable e,String msg) {
if (isShowLog && priority <= VERBOSE)
v(TAG,e,msg);
} public static void v(String tag,Throwable e,String msg) {
if (isShowLog && priority <= VERBOSE)
for(int i=0;i<e.getStackTrace().length;i++)
Log.v(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(msg)
.toString(),e);
} public static void v(String msg) {
if (isShowLog && priority <= VERBOSE)
v(TAG, msg); } public static void v(String tag, String msg) {
if (isShowLog && priority <= VERBOSE)
Log.v(tag, msg); } public static void v(Class<? > cls, String msg) {
if (isShowLog && priority <= VERBOSE)
v(TAG,cls,msg);
} public static void v(String tag,Class<?> cls,String msg) {
if (isShowLog && priority <= VERBOSE)
Log.v(tag,
new StringBuilder()
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} public static void v(Class<?> cls, String line, String msg) {
if (isShowLog && priority <= VERBOSE)
v(TAG,cls,line,msg);
} public static void v(String tag,Class<?> cls, String line, String msg) {
if (isShowLog && priority <= VERBOSE)
Log.e(tag,
new StringBuilder()
.append(line).append(COLON)
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} //-----------------------------------Log.d /**
* Log.d
* @param e
*/
public static void d(Throwable e) {
if (isShowLog && priority <= DEBUG)
d(TAG,e);
} public static void d(String tag,Throwable e) {
if (isShowLog && priority <= DEBUG)
for(int i=0;i<e.getStackTrace().length;i++)
Log.d(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(e.getMessage())
.toString());
} public static void d(Throwable e,String msg) {
if (isShowLog && priority <= DEBUG)
d(TAG,e,msg);
} public static void d(String tag,Throwable e,String msg) {
if (isShowLog && priority <= DEBUG)
for(int i=0;i<e.getStackTrace().length;i++)
Log.d(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(msg)
.toString(),e);
} public static void d(String msg) {
if (isShowLog && priority <= DEBUG)
d(TAG, msg); } public static void d(String tag, String msg) {
if (isShowLog && priority <= DEBUG)
Log.d(tag, msg); } public static void d(Class<?> cls, String msg) {
if (isShowLog && priority <= DEBUG)
d(TAG,cls,msg);
} public static void d(String tag,Class<?> cls,String msg) {
if (isShowLog && priority <= DEBUG)
Log.d(tag,
new StringBuilder()
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} public static void d(Class<?> cls, String line, String msg) {
if (isShowLog && priority <= DEBUG)
d(TAG,cls,line,msg);
} public static void d(String tag,Class<? > cls, String line, String msg) {
if (isShowLog && priority <= DEBUG)
Log.d(tag,
new StringBuilder()
.append(line).append(COLON)
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} //-----------------------------------Log.i /**
* Log.i
* @param e
*/
public static void i(Throwable e) {
if (isShowLog && priority <= INFO)
i(TAG,e);
} public static void i(String tag,Throwable e) {
if (isShowLog && priority <= INFO)
for(int i=0;i<e.getStackTrace().length;i++)
Log.i(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(e.getMessage())
.toString());
} public static void i(Throwable e,String msg) {
if (isShowLog && priority <= INFO)
i(TAG,e,msg);
} public static void i(String tag,Throwable e,String msg) {
if (isShowLog && priority <= INFO)
for(int i=0;i<e.getStackTrace().length;i++)
Log.i(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(msg)
.toString(),e);
} public static void i(String msg) {
if (isShowLog && priority <= INFO)
i(TAG, msg); } public static void i(String tag, String msg) {
if (isShowLog && priority <= INFO)
Log.i(tag, msg); } public static void i(Class<?> cls, String msg) {
if (isShowLog && priority <= INFO)
i(TAG,cls,msg);
} public static void i(String tag,Class<? > cls,String msg) {
if (isShowLog && priority <= INFO)
Log.i(tag,
new StringBuilder()
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} public static void i(Class<?> cls, String line, String msg) {
if (isShowLog && priority <= INFO)
v(TAG,cls,line,msg);
} public static void i(String tag,Class<?> cls, String line, String msg) {
if (isShowLog && priority <= INFO)
Log.i(tag,
new StringBuilder()
.append(line).append(COLON)
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} //-----------------------------------Log.w /**
* Log.w
* @param e
*/
public static void w(Throwable e) {
if (isShowLog && priority <= WARN)
w(TAG,e);
} public static void w(String tag,Throwable e) {
if (isShowLog && priority <= WARN)
for(int i=0;i<e.getStackTrace().length;i++)
Log.w(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(e.getMessage())
.toString());
} public static void w(Throwable e,String msg) {
if (isShowLog && priority <= WARN)
w(TAG,e,msg);
} public static void w(String tag,Throwable e,String msg) {
if (isShowLog && priority <= WARN)
for(int i=0;i<e.getStackTrace().length;i++)
Log.w(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(msg)
.toString(),e);
} public static void w(String msg) {
if (isShowLog && priority <= WARN)
w(TAG, msg); } public static void w(String tag, String msg) {
if (isShowLog && priority <= WARN)
Log.w(tag, msg); } public static void w(Class<?> cls, String msg) {
if (isShowLog && priority <= WARN)
w(TAG,cls,msg);
} public static void w(String tag,Class<?> cls,String msg) {
if (isShowLog && priority <= WARN)
Log.w(tag,
new StringBuilder()
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} public static void w(Class<?> cls, String line, String msg) {
if (isShowLog && priority <= WARN)
w(TAG,cls,line,msg);
} public static void w(String tag,Class<?> cls, String line, String msg) {
if (isShowLog && priority <= WARN)
Log.w(tag,
new StringBuilder()
.append(line).append(COLON)
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} //-----------------------------------Log.e /**
* Log.e
* @param e
*/
public static void e(Throwable e) {
if (isShowLog && priority <= ERROR)
e(TAG,e);
} public static void e(String tag,Throwable e) {
if (isShowLog && priority <= ERROR)
for(int i=0;i<e.getStackTrace().length;i++)
Log.e(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(e.getMessage())
.toString());
} public static void e(Throwable e,String msg) {
if (isShowLog && priority <= ERROR)
e(TAG,e,msg);
} public static void e(String tag,Throwable e,String msg) {
if (isShowLog && priority <= ERROR)
for(int i=0;i<e.getStackTrace().length;i++)
Log.e(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(msg)
.toString(),e);
} public static void e(String msg) {
if (isShowLog && priority <= ERROR)
e(TAG, msg); } public static void e(String tag, String msg) {
if (isShowLog && priority <= ERROR)
Log.e(tag, msg); } public static void e(Class<?> cls, String msg) {
if (isShowLog && priority <= ERROR)
e(TAG,cls,msg);
} public static void e(String tag,Class<?> cls,String msg) {
if (isShowLog && priority <= ERROR)
Log.e(tag,
new StringBuilder()
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} public static void e(Class<?> cls, String line, String msg) {
if (isShowLog && priority <= ERROR)
e(TAG,cls,line,msg);
} public static void e(String tag,Class<?> cls, String line, String msg) {
if (isShowLog && priority <= ERROR)
Log.w(tag,
new StringBuilder()
.append(line).append(COLON)
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} //-----------------------------------Log.wtf /**
* Log.wtf
* @param e
*/
public static void wtf(Throwable e) {
if (isShowLog && priority <= ASSERT)
wtf(TAG,e);
} public static void wtf(String tag,Throwable e) {
if (isShowLog && priority <= ASSERT)
for(int i=0;i<e.getStackTrace().length;i++)
Log.wtf(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(e.getMessage())
.toString());
} public static void wtf(Throwable e,String msg) {
if (isShowLog && priority <= ASSERT)
wtf(TAG,e,msg);
} public static void wtf(String tag,Throwable e,String msg) {
if (isShowLog && priority <= ASSERT)
for(int i=0;i<e.getStackTrace().length;i++)
Log.wtf(tag,
new StringBuilder()
.append(e.getStackTrace()[i].getLineNumber())
.append(COLON)
.append(e.getStackTrace()[i].getClassName())
.append(ARROW)
.append(e.getStackTrace()[i].getMethodName())
.append(COLON)
.append(msg)
.toString(),e);
} public static void wtf(String msg) {
if (isShowLog && priority <= ASSERT)
wtf(TAG, msg); } public static void wtf(String tag, String msg) {
if (isShowLog && priority <= ASSERT)
Log.wtf(tag, msg); } public static void wtf(Class<?> cls, String msg) {
if (isShowLog && priority <= ASSERT)
wtf(TAG,cls,msg);
} public static void wtf(String tag,Class<?> cls,String msg) {
if (isShowLog && priority <= ASSERT)
Log.wtf(tag,
new StringBuilder()
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} public static void wtf(Class<?> cls, String line, String msg) {
if (isShowLog && priority <= ASSERT)
e(TAG,cls,line,msg);
} public static void wtf(String tag,Class<? > cls, String line, String msg) {
if (isShowLog && priority <= ASSERT)
Log.wtf(tag,
new StringBuilder()
.append(line).append(COLON)
.append(cls.getSimpleName())
.append(COLON)
.append(msg)
.toString());
} //-----------------------------------System.out.print /**
* System.out.print
* @param msg
*/
public static void print(String msg){
if(isShowLog && priority <= PRINTLN)
System.out.print(msg);
} public static void print(Object obj){
if(isShowLog && priority <= PRINTLN)
System.out.print(obj);
} //-----------------------------------System.out.printf /**
* System.out.printf
* @param msg
*/
public static void printf(String msg){
if(isShowLog && priority <= PRINTLN)
System.out.printf(msg);
} //-----------------------------------System.out.println /**
* System.out.println
* @param msg
*/
public static void println(String msg){
if(isShowLog && priority <= PRINTLN)
System.out.println(msg);
} public static void println(Object obj){
if(isShowLog && priority <= PRINTLN)
System.out.println(obj);
} }
只需进行一个简单的包、方便记录和管理、
版权声明:本文博主原创文章,博客,未经同意不得转载。
经常使用Log日志打印输出的更多相关文章
- java中log日志的使用(完全版)
Commons_logging包 Apache通用日志包 他为Log4JLogger:NoOpLog:LogKitLogger:Jdk14Logger:AvalonLogger提供了一共通用的接口进行 ...
- Atitit.log日志技术的最佳实践attilax总结
Atitit.log日志技术的最佳实践attilax总结 1. 日志的意义与作用1 1.1. 日志系统是一种不可或缺的单元测试,跟踪调试工具1 2. 俩种实现[1]日志系统作为一种服务进程存在 [2] ...
- mysql general log日志
注:应一直出现http://www.cnblogs.com/hwaggLee/p/6030765.html文章中的问题 故mysql general log日志.查看具体是什么命令导致的. 打开 ge ...
- 使用触发器实现记录oracle用户登录失败信息到alert.log日志文件
前面我们说了用oracle自带的审计功能可以实现记录用户登录失败日志到数据表中(链接:http://www.54ok.cn/6778.html).今天我们来分享一下如何把用户登录失败信息记录到aler ...
- Junit测试打印详细的log日志,可以看到sql
Junit测试打印详细的log日志,可以看到sql 在log4j.xml的日志配置文件中,把日志级别从info级别调整到debug级别: <?xml version="1.0" ...
- iOS及时log日志查看工具 (iConsole)
github下载地址:https://github.com/nicklockwood/iConsole 偶然看到的一个iOS及时log日志查看工具,通过该工具,我们可以在任何想看日志的时候,通过手势呼 ...
- svn update -r m path 代码还原到某个版本(这样之前的log日志也就没了,也就是清空log日志)
[root@ok 资料库]# svn log 简历 ------------------------------------------------------------------------ r ...
- 【个人使用.Net类库】(2)Log日志记录类
开发接口程序时,要保证程序稳定运行就要时刻监控接口程序发送和接收的数据,这就需要一个日志记录的类将需要的信息记录在日志文件中,便于自己维护接口程序.(Web系统也是如此,只是对应的日志实现比这个要复杂 ...
- [转] C#实现自动化Log日志
qing2005原文地址 C#实现自动化Log日志 在开发项目的时候,我们不免要使用Log记录日志,使用最多的是Log4Net和EntLib Log,在需要记录日志的代码处加入log.Write(日志 ...
随机推荐
- hdu3664(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3664 分析:dp[i][j]表示i个数的排列中E值为j的个数.假设现在已有一个E值为j的i的排列,对于 ...
- Android_多媒体_SoundPool声音池使用
1.SoundPool概述 SoundPool就相当于一个简单的集合,可以将apk中的资源或者系统中的文件加载至内存中,使用了MediaPlayer服务区解码音频文件,用SoundPool可以播一些短 ...
- Selenium之利用Excel实现参数化
Selenium之利用Excel实现参数化 说明:我是通过Workbook方式来读取excel文件的,这次以登陆界面为例 备注:使用Workbook读取excel文件,前提是excel需要2003版本 ...
- Mac下配置Cocos2d-x3.1环境
一.前期准备 1.ADT:百度下就OK 2.NDK:百度下就OK 3.ANT: http://124.254.47.39/download/55152992/78533365/4/zip/57/132 ...
- LINUX设备驱动程序的注意事项(两)建设和执行模块
<一>:设置測试系统 首先准备好一个内核源代码树,构造一个新内核,然后安装到自己的系统中. <二>:HelloWorld模块 #inclu ...
- GString及IntelliJIdea中调试Groovy的操作步骤
今天是学习Groovy的第一天,首先我觉得学习任何一种语言都要先弄清楚这种语言的特性,因为只有了解了特性之后学习才能达到好的效果,那么groovy的特点是什么的.我觉得groovy是一种动态语言,动态 ...
- 在mysql数据库中关于日期时间字段的处理
在mysql数据库中关于日期时间字段的处理 在开发中,日期时间字段一般有如下几种设计 假设要获取2013-08-15日到2013-08-16日之间的记录 1. 直接使用日期时间类字段 相关sql语句如 ...
- AS3.0下去除flash右键菜单
这两天工作中遇到一个问题,就是网页中内嵌的flash小游戏的用户体验,当鼠标在flash上点击右键时,出现的右键菜单中会有播放,停止等选项,虽然不会造成什么漏洞,但是体验非常差.在寻找解决方案的时候, ...
- JavaScript采用append添加的元素错误
1.错误叙述性说明 于IE览器上: Uncaught HierarchyRequestError:Failed to excute 'appendChild' on 'Node':The new ch ...
- 2010多校第一题 hdu3440House Man 差分约束系统
给我们n座房子,房子的高度各不相同, 从最低的房子开始, 每次跳到更高的房子, 跳n-1次最能跳到最高的房子了,但是每次跳跃的距离不能超过d 将这些房子在一维的方向上重新摆放(但是保持输入时的相对位置 ...