1、头文件

#include <android/log.h>

2、宏定义

#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "mytest", __VA_ARGS__)

3、代码中打印

LOGD("test test test");
int i = 12;
LOGD("%d",i);

4、注意

打印字符串可以用下面两个函数

__android_log_print
__android_log_write
但是打印整数等,就必须用下面这个函数了
__android_log_print
原因参见文件/system/core/include/android/log.h,如下
 1 #include <stdarg.h>
2
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 /*
8 * Android log priority values, in ascending priority order.
9 */
10 typedef enum android_LogPriority {
11 ANDROID_LOG_UNKNOWN = 0,
12 ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
13 ANDROID_LOG_VERBOSE,
14 ANDROID_LOG_DEBUG,
15 ANDROID_LOG_INFO,
16 ANDROID_LOG_WARN,
17 ANDROID_LOG_ERROR,
18 ANDROID_LOG_FATAL,
19 ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
20 } android_LogPriority;
21
22 /*
23 * Send a simple string to the log.
24 */
25 int __android_log_write(int prio, const char *tag, const char *text);
26
27 /*
28 * Send a formatted string to the log, used like printf(fmt,...)
29 */
30 int __android_log_print(int prio, const char *tag, const char *fmt, ...)
31 #if defined(__GNUC__)
32 __attribute__ ((format(printf, 3, 4)))
33 #endif
34 ;
35
36 /*
37 * A variant of __android_log_print() that takes a va_list to list
38 * additional parameters.
39 */
40 int __android_log_vprint(int prio, const char *tag,
41 const char *fmt, va_list ap);
42
43 /*
44 * Log an assertion failure and SIGTRAP the process to have a chance
45 * to inspect it, if a debugger is attached. This uses the FATAL priority.
46 */
47 void __android_log_assert(const char *cond, const char *tag,
48 const char *fmt, ...)
49 #if defined(__GNUC__)
50 __attribute__ ((noreturn))
51 __attribute__ ((format(printf, 3, 4)))
52 #endif
53 ;
54
55 #ifdef __cplusplus
56 }
57 #endif
58
59 #endif /* _ANDROID_LOG_H */


   





更多相关文章

  1. 箭头函数的基础使用
  2. Python技巧匿名函数、回调函数和高阶函数
  3. USB UMS MTP设置过程 (二) UsbDeviceManager.java
  4. android 5.1禁止休眠
  5. Android应用程序组件Content Provider的共享数据更新通知机制分
  6. Android(安卓)API 中文(76)——AdapterView.OnItemLongClickListen
  7. Java工程中调用Android库出现“Stub!”错误
  8. Android的NDK开发(3)————JNI数据类型的详解
  9. 初学Android的surfaceView

随机推荐

  1. Android(安卓)Audio 分析
  2. 8.3facebook分享后不回调结果原因,java标
  3. ANDROID_SDK_HOME的设置
  4. 深入了解Android图形管道-part1
  5. android 系统启动过程中加入tcpdump和log
  6. Android(安卓)Studio 断点调试和高级调试
  7. android仿人人网右边可推出的效果
  8. Android(安卓)2.3 NDK的新特性
  9. activity-alias的使用
  10. Android学习笔记-ProgressBar和ListView