经常使用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(日志 ...
随机推荐
- 在CodeBlocks 开发环境中配置使用OpenCV (ubuntu系统)
CodeBlocks是一个开放源代码的全功能的跨平台C/C++集成开发环境.CodeBlocks由纯粹的C++语言开发完毕,它使用了蓍名的图形界面库wxWidgets.对于追求完美的C++程序猿,再也 ...
- GOJ1150(矩阵快速幂)
sum Time Limit: 1000ms Problem Description: 给定a和n,计算a+aa+aaa+aaaa+...+a...a(n个a) 的和. Input: 测试数据有多组, ...
- Android入门之简单短信发送器
效果图: manifest.xml 文件中加入 <uses-permission android:name="android.permission.SEND_SMS"/&g ...
- 采用DWR、maven保存数据到数据库
一.原理: Ajax是时下比较流行的一种web界面设计新思路,其核心思想是从浏览器获取XMLHttp对象与服务器端进行交互. DWR(Direct Web Remoting)就是实现了这种Ajax技术 ...
- 【android自己定义控件】自己定义View属性
1.自己定义View的属性 2.在View的构造方法中获得我们自己定义的属性 3.重写onMesure 4.重写onDraw 3这个步骤不是必须,当然了大部分情况下还是须要重写的. 1.自己定义Vie ...
- 算法学习 - 图的广度优先遍历(BFS) (C++)
广度优先遍历 广度优先遍历是非经常见和普遍的一种图的遍历方法了,除了BFS还有DFS也就是深度优先遍历方法.我在我下一篇博客里面会写. 遍历过程 相信每一个看这篇博客的人,都能看懂邻接链表存储图. 不 ...
- android4.0 USB Camera示例(五个辅助)jpg压缩
前的最后一个 我们说,一个直接yuv变成jpg该功能 但是转换不成功 主要功能是yuv420转jpg的 根据研究发现 yuv420的序列是这种 YYYY YYYY UVUV 而yuv422的隔行扫描的 ...
- 简单fcgi程序
1.头文件 #include <fcgi_stdio.h> 2.while(FCGI_Accept()>=0)//这里进入循环,前台每请求一次fcgi服务,就循环一次 循环内处理: ...
- crm工作机会实体
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; public class Opport ...
- IAR FOR ARM 各版本号,须要的大家能够收藏了
首先感谢大家的支持与关注,如今应该又一次编辑这篇文章了,这篇文章是非常久曾经不知在什么地方Copy过来的, 非常多问题不知怎么解决,如今我用的是KEIL for arm. 用过Keil和IAR,个人感 ...