/**
* 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日志打印输出的更多相关文章

  1. java中log日志的使用(完全版)

    Commons_logging包 Apache通用日志包 他为Log4JLogger:NoOpLog:LogKitLogger:Jdk14Logger:AvalonLogger提供了一共通用的接口进行 ...

  2. Atitit.log日志技术的最佳实践attilax总结

    Atitit.log日志技术的最佳实践attilax总结 1. 日志的意义与作用1 1.1. 日志系统是一种不可或缺的单元测试,跟踪调试工具1 2. 俩种实现[1]日志系统作为一种服务进程存在 [2] ...

  3. mysql general log日志

    注:应一直出现http://www.cnblogs.com/hwaggLee/p/6030765.html文章中的问题 故mysql general log日志.查看具体是什么命令导致的. 打开 ge ...

  4. 使用触发器实现记录oracle用户登录失败信息到alert.log日志文件

    前面我们说了用oracle自带的审计功能可以实现记录用户登录失败日志到数据表中(链接:http://www.54ok.cn/6778.html).今天我们来分享一下如何把用户登录失败信息记录到aler ...

  5. Junit测试打印详细的log日志,可以看到sql

    Junit测试打印详细的log日志,可以看到sql 在log4j.xml的日志配置文件中,把日志级别从info级别调整到debug级别: <?xml version="1.0" ...

  6. iOS及时log日志查看工具 (iConsole)

    github下载地址:https://github.com/nicklockwood/iConsole 偶然看到的一个iOS及时log日志查看工具,通过该工具,我们可以在任何想看日志的时候,通过手势呼 ...

  7. svn update -r m path 代码还原到某个版本(这样之前的log日志也就没了,也就是清空log日志)

    [root@ok 资料库]# svn log 简历 ------------------------------------------------------------------------ r ...

  8. 【个人使用.Net类库】(2)Log日志记录类

    开发接口程序时,要保证程序稳定运行就要时刻监控接口程序发送和接收的数据,这就需要一个日志记录的类将需要的信息记录在日志文件中,便于自己维护接口程序.(Web系统也是如此,只是对应的日志实现比这个要复杂 ...

  9. [转] C#实现自动化Log日志

    qing2005原文地址 C#实现自动化Log日志 在开发项目的时候,我们不免要使用Log记录日志,使用最多的是Log4Net和EntLib Log,在需要记录日志的代码处加入log.Write(日志 ...

随机推荐

  1. LeetCode_Merge Two Sorted Lists

    一.题目 Merge Two Sorted Lists My Submissions Merge two sorted linked lists and return it as a new list ...

  2. 基于Opencv图像处理的时时头像採集试验

    2014 4.20 近期想做一个关于图像处理的软件玩玩,可惜也没有什么特别的想法,就当玩玩好了,准备用Opencv开源库实现下简单的功能吧. Opencv是一个专业的图像处理库,里面有非常多基础函数能 ...

  3. 【C#遗补】之Char.IsDigit和Char.IsNumber的区别

    原文:[C#遗补]之Char.IsDigit和Char.IsNumber的区别 Char中IsDigit和IsNumber的两个方法都是用来判断字符是否是数字的,那他们有什么区别 IsDigit    ...

  4. PHP_SELF、 SCRIPT_NAME、 REQUEST_URI差别

    $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在使用方法上是很相似的,他们返回的都是与当前正在使用的页面地址有关 ...

  5. BCM wifi分析

    一个:载入中wifi驱动模块 在hardware/libhardware_legacy/wifi/wifi.c调用函数 insmod(DRIVER_MODULE_PATH, DRIVER_MODULE ...

  6. HDU 3639 Hawk-and-Chicken(良好的沟通)

    HDU 3639 Hawk-and-Chicken 题目链接 题意:就是在一个有向图上,满足传递关系,比方a->b, b->c,那么c能够得到2的支持,问得到支持最大的是谁,而且输出这些人 ...

  7. c语言来实现c++

    闲来没事,看了看sqlite的源代码,突然想用c实现c++,写了例如以下demo,自我感觉不错 #include <stdio.h> #include <stdlib.h> s ...

  8. 在Java中怎样逐行地写文件?

    下边是写东西到一个文件里的Java代码. 执行后每一次,一个新的文件被创建,而且之前一个也将会被新的文件替代.这和给文件追加内容是不同的. public static void writeFile1( ...

  9. duilib底层机制剖析:窗口类与窗口句柄的关联

    转载请说明原出处.谢谢~~ 看到群里朋友有人讨论WTL中的thunk技术,让我联想到了duilib的类似技术. 这些技术都是为了解决c++封装的窗口类与窗口句柄的关联问题. 这里是三篇关于thunk技 ...

  10. pygame系列

    在接下来的blog中,会有一系列的文章来介绍关于pygame的内容,pygame系列偷自http://www.cnblogs.com/hongten/p/hongten_pygame_install. ...