package com.geniuseoe.uitl;
import android.util.Log;
public class CommonLog {
private String tag = "CommonLog";
public static int logLevel = Log.VERBOSE;
public static boolean isDebug = true;
public CommonLog() { }
public CommonLog(String tag) {
this.tag = tag;
}
public void setTag(String tag) {
this.tag = tag;
}
private String getFunctionName() {
StackTraceElement[] sts = Thread.currentThread().getStackTrace();
if (sts == null) {
return null;
}
for (StackTraceElement st:sts) {
if (st.isNativeMethod()) {
continue;
}
if (st.getClassName().equals(Thread.class.getName())) {
continue;
}
if (st.getClassName().equals(this.getClass().getName())) {
continue;
}
return "["+Thread.currentThread().getId()+": "+st.getFileName()+":"+st.getLineNumber()+"]";
}
return null;
}
public void info(Object str) {
if (logLevel <= Log.INFO) {
String name = getFunctionName();
String ls=(name==null?str.toString():(name+" - "+str));
Log.i(tag, ls);
}
}
public void i(Object str) {
if (isDebug) {
info(str);
}
}
public void verbose(Object str) {
if (logLevel <= Log.VERBOSE) {
String name = getFunctionName();
String ls=(name==null?str.toString():(name+" - "+str));
Log.v(tag, ls);
}
}
public void v(Object str) {
if (isDebug) {
verbose(str);
}
}
public void warn(Object str) {
if (logLevel <= Log.WARN) {
String name = getFunctionName();
String ls=(name==null?str.toString():(name+" - "+str));
Log.w(tag, ls);
}
}
public void w(Object str) {
if (isDebug) {
warn(str);
}
}
public void error(Object str) {
if (logLevel <= Log.ERROR) {
String name = getFunctionName();
String ls=(name==null?str.toString():(name+" - "+str));
Log.e(tag, ls);
}
}
public void error(Exception ex) {
if (logLevel <= Log.ERROR) {
StringBuffer sb = new StringBuffer();
String name = getFunctionName();
StackTraceElement[] sts = ex.getStackTrace();
if (name != null) {
sb.append(name+" - "+ex+"\r\n");
} else {
sb.append(ex+"\r\n");
}
if (sts != null && sts.length > 0) {
for (StackTraceElement st:sts) {
if (st != null) {
sb.append("[ "+st.getFileName()+":"+st.getLineNumber()+" ]\r\n");
}
}
}
Log.e(tag, sb.toString());
}
}
public void e(Object str) {
if (isDebug) {
error(str);
}
}
public void e(Exception ex) {
if (isDebug) {
error(ex);
}
}
public void debug(Object str) {
if (logLevel <= Log.DEBUG) {
String name = getFunctionName();
String ls = (name == null?str.toString():(name+" - "+str));
Log.d(tag, ls);
}
}
public void d(Object str) {
if (isDebug) {
debug(str);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Log打印类的封装(android)
共32个文件
class:10个
png:6个
java:5个
5星 · 超过95%的资源 需积分: 17 87 下载量 51 浏览量
2012-08-01
22:24:06
上传
评论 4
收藏 63KB ZIP 举报
温馨提示
RT,android Log打印类的封装 可以打印出当前信息是在哪个类文件的第几行打印的 同时包括当前线程ID信息 方便童鞋们快速调试程序,解决BUG
资源推荐
资源详情
资源评论
收起资源包目录
DebugDemo.zip (32个子文件)
DebugDemo
AndroidManifest.xml 739B
res
layout
main.xml 773B
drawable-ldpi
ic_launcher.png 2KB
drawable-mdpi
ic_launcher.png 3KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 184B
proguard.cfg 1KB
src
com
geniuseoe
uitl
LogFactory.java 525B
CommonLog.java 3KB
demo
SubThread.java 327B
DebugDemoActivity.java 2KB
bin
classes
com
geniuseoe
uitl
LogFactory.class 974B
CommonLog.class 4KB
demo
DebugDemoActivity.class 2KB
R.class 531B
R$layout.class 394B
R$attr.class 340B
SubThread.class 622B
R$id.class 416B
R$string.class 427B
R$drawable.class 407B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-mdpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
DebugDemo.apk 16KB
classes.dex 7KB
resources.ap_ 10KB
.classpath 364B
assets
project.properties 360B
.settings
org.eclipse.core.resources.prefs 88B
.project 845B
gen
com
geniuseoe
demo
R.java 796B
共 32 条
- 1
蓝斯
- 粉丝: 1302
- 资源: 33
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页