There are three step in total

step one:

add "LOCAL_LDLIBS := -llog " to your android.mk file

like:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := hellolog
LOCAL_SRC_FILES := native.c
include $(BUILD_SHARED_LIBRARY)


step two:

include <android/log.h> as header in you c file, and define LOG_TAG、LOGE(...)like:

#include <android/log.h>
#define LOG_TAG "plus.c"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)


you can also define a yourlog.h file, define all kinds of log, then include this into your c file, like:

=====mylog.h=======

#include <jni.h>
#include <android/log.h>

#define LOG_TAG "hgllog.h"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)

step three:

use yourself define LOGE() print info as you want, like:

LOGE("this is log info string....");

LOGE("this is log info string.... and str is %s", str);


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Maven设置utf8编码格式
  2. 11个顶级 JavaScript 日历插件[每日前端
  3. Centos给文件设置了777权限仍不能访问解
  4. 如何开发跨框架组件?[每日前端夜话0xA6]
  5. 前端与后端开发中技术差异的全面对比[每
  6. k8s-kubernetes 入门
  7. 用 ref 访问 Vue.js 程序中的 DOM[每日前
  8. Android(安卓)在一个程序中启动另一个程
  9. MySQL中自增ID起始值修改方法
  10. MySQL出现SELECT list is not in GROUP B