[Android]Log打印
2024-09-16 11:18:06
package com.lurencun.android.system; import android.util.Log; public class ExLog { static final String TAG = ExLog.class.getSimpleName(); /**
* 输出调试信息(System.out),并在调试输入信息中附带当前代码在哪个类哪一行的额外数据。
* @param message 调试信息
*/
public static void l(String message){
StackTraceElement ele = Thread.currentThread().getStackTrace()[3];
int line = ele.getLineNumber();
String clazz = ele.getClassName();
System.out.println(":::: @"+clazz+" -> "+line+" :::: "+message);
} /**
* 取得当前代码所在的方法名
* @return 当前方法名
*/
public static String getCurrentMethodName(){
// 0 getThreadStackTrce
// 1 getStackTrace
// 2 * this method: getCurrentMethodName
// 3 your method
return Thread.currentThread().getStackTrace()[3].getMethodName();
} /**
* 输出方法调用链
* @param object 对象
*/
public static void logCurrentMethodChain(Object object){
StackTraceElement[] es = Thread.currentThread().getStackTrace();
long time = System.currentTimeMillis();
Log.d(TAG, String.format("###### Object(%s) Method Chain ###### @Time( %d )", object.getClass().getSimpleName(), time));
for(StackTraceElement e : es){
String msg = String.format("### Method Chain ### Caller:%s ->:%s", e.getClassName(),e.getMethodName());
Log.d(TAG, msg);
}
} /**
* 输出当前方法调用
* @param object 对象
*/
public static void logCurrentMethod(Object object){
String methodName = Thread.currentThread().getStackTrace()[3].getMethodName();
long time = System.currentTimeMillis();
String msg = String.format("###### Calling Method ###### Object(%s) -> %s @Time( %d )", object.getClass().getSimpleName(),methodName, time);
Log.d(TAG, msg);
} }
最新文章
- CST时间转换成 yyyy-MM-dd格式
- centos更改默认语言
- 李洪强iOS开发之宏定义方法来初始化一个单例对象
- algorithm@ find the shortest path in a graph using BFS
- ios 字符串替换方法
- Tomcat8 配置Oracle11g数据源
- poj 3320 Jessica's Reading Problem(尺取法)
- CentOS6.5与XP双系统安装
- jsp获取枚举的值
- redis中的事务
- 测试与发布(Alpha版本)
- Eclipse背景颜色改动
- 8_python连接数据库
- 《阿里巴巴Android编码规范》阅读纪要(二)
- python中pip升级
- mysql 创建数据库,添加用户,用户授权
- w​i​n​d​o​w​s​ ​s​e​r​v​e​r​ ​2​0​0​8​ ​r​2​ ​启​用​索​引(转)
- [Ubuntu] geoip-bin 程序包 - 查询 IP 归属地
- 为什么使彩色图变灰RGB的权重会固定(R:0.299 G:0.587 B:0.114)?
- 网页方式访问 QQ 小说书架