/**
* 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. [华为机试练习题]50.求M的N次方的最后三位

    题目 描写叙述: 正整数M 的N次方有可能是一个很大的数字,我们仅仅求该数字的最后三位 例1: 比方输入5和3 ,5的3次方为125.则输出为125 例2: 比方输入2和10 2的10次方为1024 ...

  2. Wix打包系列(七) 添加系统必备组件的安装程序

    原文:Wix打包系列(七) 添加系统必备组件的安装程序 我们知道在vs的打包工程中添加系统必备组件是一件很容易的事情,那么在wix中如何检测系统必备组件并在安装过程中安装这些组件.这里以.Net Fr ...

  3. [cocos2dx-lua]&quot;Hello Lua&quot;分析

    一年之前学的cocos2dx,那时候还是用C++编写的.但学完之后就找的一个新的方向--Unity3D开发的岗位,对我而言是一个新方向,那时候经过了几个月的每天熬夜奋战,从"0"基 ...

  4. HDU - 2825 Wireless Password(AC自己主动机+DP)

    Description Liyuan lives in a old apartment. One day, he suddenly found that there was a wireless ne ...

  5. Codeforces 549G. Happy Line 馋

    非常有趣的贪婪: Let's reformulate the condition in terms of a certain height the towers, which will be on t ...

  6. ajax相关体会

    参考原文: 例子:http://blog.csdn.net/beijiguangyong/article/details/7725596 原理讲解:http://www.cnblogs.com/min ...

  7. shufe前辈名师

    前辈名师 姓名 现职/原职 郭秉文 中国现代大学之父.国立东南大学校长.哥伦比亚大学教育学博士,该校第一任校长.为了纪念郭秉文先生,勉励优秀学子,郭夏瑜女士在上海财经大学等校设立了“郭秉文奖学金” 马 ...

  8. bootstrap之DumpWindowHierarchy

    DumpWindowHierarchy package io.appium.android.bootstrap.handler; import android.os.Environment; impo ...

  9. Allegro绘制PCB流程

    单位换算 1mil = 0.0254 mm 1mm = 39.3701 mil 默认情况下我们更倾向于使用mil单位绘制PCB板. 1 新建工程,File --> New... --> [ ...

  10. 足球和oracle系列(3):oracle过程排名,世界杯第二回合战罢到来!

    足球与oracle系列(3):oracle进程排名.世界杯次回合即将战罢! 声明:        这不是技术文档,既然学来几招oracle简单招式.就忍不了在人前卖弄几下.纯为茶余饭后与数朋库友的插科 ...