经常使用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(日志 ...
随机推荐
- (step 8.2.13)hdu 1524(A Chess Game)
题目大意 : 在一个 有向无环图顶点上面有几个棋子, 2个人轮流操作, 每次操作就是找一个棋子往它能够移 动的地方移动一格, 不能操作的人输. 输入第一行 为一个 N , 表示有 N 个顶点 0 -& ...
- Filter技术+职责链模式
Filter是一个过滤器,存在Webclient与请求的资源之间.这里的资源能够说是jsp或servlet.它的作用就是在请求达到资源之前,先对请求进行预处理.而且也能够对servlet处理后的res ...
- hdu2870(dp求最大子矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2870 分析:分别转换成'a','b','c'三种来求,其实就跟hdu1505一样了... #inclu ...
- svn rm --keep-local ./QueryParser_kill.logs
svn rm --keep-local ./QueryParser_kill.logs
- 共享库方案解决WAS中JAR包冲突
实现步骤: 1. 准备共享库JAR包 commons-httpclient-3.1.jar httpclient-4.3.3.jar httpcore-4.3.2.jar httpmim ...
- win7问题解决,凭据管理器和无法访问,不允许一个用户使用一个以上用户名与服务器或共享资源进行多重连接。
WIN7凭据管理器,如果你用一个帐号远程登录以后在电脑中会记住这个信息,假如你想用另外的帐号,那么就到控制面板-凭据管理器里中进行修改或者删除. 如果你登录以后提示,“无法访问.不允许一个用户使用一个 ...
- HDU2647-Reward(拓扑排序)
Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- 【NIO】dawn在buffer用法
网络编程,buffer它用于数据传输到网络上的集线器应用程序,不用说,一个重要的线.提到buffer我不能说什么零拷贝,buffer什么内存管理,在dawn在,基于directbuffer再次能够实现 ...
- C语言获取文件SHA1哈希
安全散列算法(Secure Hash Algorithm)主要适用于数字签名标准 (Digital Signature Standard DSS)它定义了数字签名算法(Digital Signatur ...
- linux free
在Linux下查看内存我们一般用command free [root@nonamelinux ~]# free total used free s ...