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 ...
随机推荐
- mysql truncate table命令使用总结
truncate使用注意 由于上过truncate table a_table命令一次当,将教训记录下来,以示警戒! mysql truncate table a_table命令受影响结果说明 ...
- .net网站上传图片换电脑不显示 当不用网站的IP地址访问图片,只用相对路径访问时,在发布网站的时候,将上传图片的目标文件夹,包含在项目中再发布即可。
.net网站上传图片换电脑不显示 当不用网站的IP地址访问图片,只用相对路径访问时,在发布网站的时候,将上传图片的目标文件夹,包含在项目中再发布即可.
- Linaro/Yocto/Openwrt
http://en.wikipedia.org/wiki/Linaro Linaro From Wikipedia, the free encyclopedia This article ap ...
- java 是 传值还是传址 Pass-by-value or Pass-by-reference
原文在此,写的非常好,解答了我的疑问 http://www.javadude.com/articles/passbyvalue.htm 首先放上一段代码,我是在找寻这段代码的内部原理的时候,在stac ...
- angularJS contenteditable 指令双向绑定
项目遇到需求有点奇葩:双击div使其可编辑,失去焦点后进行数据绑定 通过自定义指令完成 好了上代码: .directive('contentEditable', function() { return ...
- OpenCV 的四大模块
前言 我们都知道 OpenCV 是一个开源的计算机视觉库,那么里面到底有哪些东西?本文将为你解答这个问题. 模块一:CV 这个模块是 OpenCV 的核心,它包含了基本的图像处理函数和高级的计算机视觉 ...
- 简述C++中的多态机制
前言 封装性,继承性,多态性是面向对象语言的三大特性.其中封装,继承好理解,而多态的概念让许多初学者感到困惑.本文将讲述C++中多态的概念以及多态的实现机制. 什么是多态? 多态就是多种形态,就是许多 ...
- Python 008- 游戏2048
#-*- coding:utf-8 -*- import curses from random import randrange, choice # generate and place new ti ...
- finding friends with mapreduce
http://stevekrenzel.com/finding-friends-with-mapreduce
- 点击文本选中checkbox
<checbox文本编辑/> : 只点击checkbox时,才可以选中,点击文本时无法选中 <label><checbox文本编辑/></label ...