android开发中怎么通过Log函数输出当前行号和当前函数名
public class Debug {
public static int line(Exception e) {
StackTraceElement[] trace = e.getStackTrace();
if (trace == null || trace.length == 0)
return -1; //
return trace[0].getLineNumber();
}
public static String fun(Exception e) {
StackTraceElement[] trace = e.getStackTrace();
if (trace == null)
return ""; //
return trace[0].getMethodName();
}
}
使用场景:
public class test {
public static String DI(Exception e) {
return Debug.line(e)+"|"+Debug.fun(e)+"|";
}
public test() {
Log.d(TAG, DI(new Exception())); //这里就输出我们需要的debug信息了
}
}
另一种使用形式:
public class DebugInfo extends Exception {
public int line() {
StackTraceElement[] trace = getStackTrace();
if (trace == null || trace.length == 0) {
return -1;
}
return trace[0].getLineNumber();
}
public String fun() {
StackTraceElement[] trace = getStackTrace();
if (trace == null || trace.length == 0) {
return "";
}
return trace[0].getMethodName();
}
public DebugInfo() {
super();
}
@Override
public String toString() {
return line() + "|" + fun() + "|";
}
}
使用方法
Log.d(TAG, new DebugInfo() + "hello world!");
public class DebugInfo {
public static int line(StackTraceElement e) {
return e.getLineNumber();
}
public static String method(StackTraceElement e) {
return e.getMethodName();
}
public static String info(StackTraceElement e) {
String ret = line(e) + "|" + method(e) + "|";
return ret;
}
}
android开发中怎么通过Log函数输出当前行号和当前函数名的更多相关文章
- 【转载】Eclipse:Android开发中如何查看System.out.println的输出内容
Android开发中在代码中通过System.out.println的输出内容不知道去哪了,在console视图中看不到.而通过Log.i之类的要在Logcat视图中看到,夹杂了太多的其它App及底层 ...
- Android开发中,那些让您觉得相见恨晚的方法、类或接口
Android开发中,那些让你觉得相见恨晚的方法.类或接口本篇文章内容提取自知乎Android开发中,有哪些让你觉得相见恨晚的方法.类或接口?,其实有一部是JAVA的,但是在android开发中也算常 ...
- Android开发中常见的设计模式
对于开发人员来说,设计模式有时候就是一道坎,但是设计模式又非常有用,过了这道坎,它可以让你水平提高一个档次.而在android开发中,必要的了解一些设计模式又是非常有必要的.对于想系统的学习设计模式的 ...
- Intent 对象在 Android 开发中的应用
转自(http://www.ibm.com/developerworks/cn/opensource/os-cn-android-intent/) Android 是一个开放性移动开发平台,运行在该平 ...
- 在android开发中使用multdex的方法-IT蓝豹为你整理
Android系统在安装应用时,往往需要优化Dex,而由于处理工具DexOpt对id数目的限制,导致其处理的数目不能超过65536个,因此在Android开发中,需要使用到MultiDex来解决这个问 ...
- android开发中的5种存储数据方式
数据存储在开发中是使用最频繁的,根据不同的情况选择不同的存储数据方式对于提高开发效率很有帮助.下面笔者在主要介绍Android平台中实现数据存储的5种方式. 1.使用SharedPreferences ...
- Android学习探索之Java 8 在Android 开发中的应用
前言: Java 8推出已经将近2年多了,引入很多革命性变化,加入了函数式编程的特征,使基于行为的编程成为可能,同时减化了各种设计模式的实现方式,是Java有史以来最重要的更新.但是Android上, ...
- Android开发中的输入合法性检验
Why ? 合法性检查对于程序的健壮性具有重要作用.在Android开发中,良好的合法性检查设计机制可以使程序更加清晰,产生bug更少,交互更加友好. What ? 合法性检查的目的在于确定边界.对于 ...
- 怎样实现了捕获应用中的日志在android开发中
怎样实现了捕获应用中的日志在android开发中,大家可研究一下. Process mLogcatProc = null; BufferedReader reader = null; try { mL ...
随机推荐
- centos7+ 安装Docker 17.03.2
cnetos7 安装 docker17.03.2 升级内核 http://m.blog.csdn.net/article/details?id=52047780 注意切换内核时查看 新内核位置 awk ...
- 有关C/C++指针的经典面试题(转)
参考一: 有关C/C++指针的经典面试题 0.预备知识,最基础的指针 其实最基础的指针也就应该如下面代码: int a; int* p=&a; 也就是说,声明了一个int变量a,然后声明一个i ...
- 【bzoi2006】【狼抓兔子】【最小割】
Description Source: Beijing2006 [BJOI2006] 八中OJ上本题链接:http://www.lydsy.com/JudgeOnline/problem.php?id ...
- C++获取站点的ip地址
#include "stdafx.h" #include <winsock2.h> #pragma comment (lib,"ws2_32.lib&q ...
- 苦逼IT才能看懂的笑话
这是苦逼IT才能看懂的笑话1.栈和队列的区别是啥? 吃多了拉就是队列:吃多了吐就是栈 2.世界上最遥远的距离不是生与死,而是你亲手制造的BUG就在你眼前,你却怎么都找不到她... 3.<c++程 ...
- wdcp新开站点或绑定域名打不开或无法访问的问题
一 用IP可以打开,但用域名打开网站显示到默认页面1 站点列表里是否有相应的网站信息 2 检查有没站点配置文件后台 >系统管理 >文件管理器 >虚拟主机站点文件(nginx,ap ...
- vmware克隆一台机器后修改etho
1 vi /etc/udev/rules.d/70-persistent-net.rules 2 注释NAME="eth0"的内容 3 将NAME="eth1" ...
- 在Livemedia的基础上开发自己的流媒体客户端 V 0.01
在Livemedia的基础上开发自己的流媒体客户端 V 0.01 桂堂东 xiaoguizi@gmail.com 2004-10 2004-12 友情申明: 本文档适合已经从事流媒体传输工作或者对网络 ...
- gcc參数总结
/*gcc 命令总结*/ 补充下gcc的知识,免得被大自然说编译原理不行.. 1.-o 參数 參数说明: -o參数用来指定生成程序的名字 gcc test.c 会编译出一个名为a.out的程序 gcc ...
- scikit-learn:4.2. Feature extraction(特征提取,不是特征选择)
http://scikit-learn.org/stable/modules/feature_extraction.html 带病在网吧里. ..... 写.求支持. .. 1.首先澄清两个概念:特征 ...