Android Logging
Here is HauteLook’s logger class from our Android Code Library. It displays class name, method name and line number per line of log message.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
package com.hautelook.android.lib.logger; /** * @authorjimmy@hautelook.com * @copyright 2011 HauteLook * * Description: * Simple logger that displays: class name, method name and line number * * * Usage: * * Use this class directly or customize it by extending it. * * HLlog.i(""); * HLLog.i("called"); * HLLog.i("called","tag"); * * L.i(); * L.i("called"); * L.i("called","tag"); * * Sub-classing example: * * // C.DEBUG = boolean true/false (project specific constant class) * * public class L extends HLLog { * * public static String DEFAULT_TAG = "HauteLook"; * * public static void i() { * if(C.DEBUG) callLogger("i", DEFAULT_TAG, ""); * } * * public static void i(String message) { * if(C.DEBUG) callLogger("i", DEFAULT_TAG, message); * } * * public static void i(String message, String tag) { * if(C.DEBUG) callLogger("i", tag, message); * } * * } * */ import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import android.util.Log; @SuppressWarnings("unused")publicclass HLLog { publicstatic String DEFAULT_TAG ="HauteLookLib"; finalstaticintdepth = 4; publicstaticvoid i(String message) { callLogger("i", DEFAULT_TAG, message); } publicstaticvoid i(String message, String tag) { callLogger("i", tag, message); } publicstaticvoid d(String message) { callLogger("d", DEFAULT_TAG, message); } publicstaticvoid d(String message, String tag) { callLogger("d", tag, message); } publicstaticvoid e(String message) { callLogger("e", DEFAULT_TAG, message); } publicstaticvoid e(String message, String tag) { callLogger("e", tag, message); } publicstaticvoid w(String message) { callLogger("w", DEFAULT_TAG, message); } publicstaticvoid w(String message, String tag) { callLogger("w", tag, message); } publicstaticvoid v(String message) { callLogger("v", DEFAULT_TAG, message); } publicstaticvoid v(String message, String tag) { callLogger("v", tag, message); } @SuppressWarnings("rawtypes") publicstaticvoid callLogger(String methodName, String tag, String message) { final StackTraceElement[] ste = Thread.currentThread().getStackTrace(); try { Class cls = Class.forName("android.util.Log"); Method method = cls.getMethod(methodName, String.class, String.class); method.invoke(null, tag, getTrace(ste) + message); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } publicstatic String getTrace(StackTraceElement[] ste) { return"[" + getClassName(ste) + "][" + getMethodName(ste) + "][" + getLineNumber(ste) + "] "; } publicstatic String getClassPackage(StackTraceElement[] ste) { return ste[depth].getClassName(); } publicstatic String getClassName(StackTraceElement[] ste) { String[] temp = ste[depth].getClassName().split("\\."); return temp[temp.length - 1]; } publicstatic String getMethodName(StackTraceElement[] ste) { return ste[depth].getMethodName(); } publicstaticint getLineNumber(StackTraceElement[] ste) { return ste[depth].getLineNumber(); } } |
Android Logging的更多相关文章
- Android Native 代码NDK开发学习笔记
引用:http://www.kunli.info/2011/08/21/android-native-code-study-note/ JNI,全称Java Native Interface,是用于让 ...
- Android Debugging
Debugging methods for Android Contents [hide] 1 Debuggers 1.1 Kernel and User co-debug with GDB on ...
- 【转】Android使用Log4j例子
Step 1 Download Log4J library from http://logging.apache.org/log4j/1.2/download.html Step 2 Configur ...
- 6、android 普通日志输出到SD卡
这是本人见过写博文最负责的一个人: http://www.crifan.com/android_try_use_android_logging_log4j_to_output_log_to_sd_ca ...
- Android中使用logwrapper来重定向应用程序的标准输出
在Android应用程序调试中,有时候第三方应用程序的日志输出是通过printf之类的标准函数输出的,logcat不能捕获这些日志,一个方法是使用logwrapper命令来执行第三方应用程序,logw ...
- android从应用到驱动之—camera(2)---cameraHAL的实现
本文是camera系列博客,上一篇是: android从应用到驱动之-camera(1)---程序调用流程 本来想用这一篇博客把cameraHAL的实现和流程都给写完的.搞了半天,东西实在是太多了.这 ...
- android从应用到驱动之—camera(2)---cameraHAL的实现
本来想用这一篇博客把cameraHAL的实现和流程都给写完的.搞了半天,东西实在是太多了.这篇先写cameraHAL的基本实现框架,下一篇在具体写camerahal的流程吧. cameraHAL的实现 ...
- android开发教程(八)——环境搭建之java-ndk
目录 android ndk是android用于开发本地代码的开发工具包.它提供C/C++交叉编译工具.android内核.驱动.已有的C/C++代码,都需要ndk来支持开发. 目前支持以下平台:ar ...
- Android 启动过程总结
SystemServer的启动 frameworks/base/services/java/com/android/server/SystemServer.java: run() 其中调用Activi ...
随机推荐
- Cookie与Session的复习
Cookie Cookie是HTTP协议制定的.先由服务器保存Cookie到浏览器,再下次浏览器请求服务器时把上一次请求得到Cookie再归还给服务器.由服务器创建保存到客户端浏览器的一个键值对(由服 ...
- 如何实现查询显示N个工作日有效期内的数据
功能点分析:要显示N个工作日有效期内的数据,需要考虑: 1. 可以给每条数据增加一个有效期时间字段,查询时只显示有效期之前的数据,如有效期为七天,数据的创建时间是2014-07-21,那七个工作日有效 ...
- Java8函数式接口和Lambda表达式
两者关系: Lambda表达式就是函数式接口(FunctionalInterface)实现的快捷方式,它相当于函数式接口实现的实例,因为在方法中可以使用Object作为参数,所以把Lambda表达式作 ...
- 移动终端App测试点归纳
以下所有测试最后必须在真机上完整的执行. 1 安装.卸载测试 1.1 在真机上.第三方软件(xy苹果助手.91.安卓助手)的安装与卸载 1.2 安装在手机卡上 或 SD卡上 (不同的IOS和安卓版本) ...
- PHP redis client封装
config1.inc.php if (!isset($_REQUEST['pageName']) || $_REQUEST['pageName'] != 'txl-app-test') { $CON ...
- thinkphp5的程序部署到虚拟主机的配置
thinkphp5的程序部署到虚拟主机的配置 建议不要,因为这些目录文件会全部保留,那么没办法的时候咋整 1 htdocs 虚拟主机上的 把public/index.php修改 改动后的放到 ht ...
- Crawlspider的自动爬取
引子 : 如果想要爬取 糗事百科 的全栈数据的方法 ? 方法一 : 基于scrapy框架中的scrapy的递归爬取进行实现(requests模块递归回调parse方法) . 方法二 : 基于Crawl ...
- Sping实战之通过JAVA代码装配Bean
尽管在很多场景下通过组件扫描和自动装配实现Spring的自动化配置是更为推荐的方式,但有时候自动化配置的方案行不通,因此需要明确配置Spring.比如说,你想要将第三方库中的组件装配到你的应用中,在这 ...
- 构建一个完整的DNS系统
人心不同 各如其面 如之奈何 如之奈何 ——引子 我们的目标很明了——构建一个具有根的.私有的DNS(Domain Name System). 这里不会陈述太多关于DNS与BIND的基础知识,如果 ...
- Remote error: Provider not exported: DataSetProvider1
Remote error: Provider not exported: DataSetProvider1 是服务端的问题,ServerMethodsUnit1.cpp窗体上添加DataSetProv ...