android ndk开发之Log日志(一)

//直接上代码:文件名my_log.h

 

/*

 * my_log.h

 *

 *  Created on: 2016-7-6

 *      Author: zhangyan

 */

 

#ifndef MY_LOG_H_

#define MY_LOG_H_

#include <android/log.h>

#define MY_LOG_LEVEL_VERBOSE 1

#define MY_LOG_LEVEL_DEBUG 2

#define MY_LOG_LEVEL_INFO 3

#define MY_LOG_LEVEL_WARNING 4

#define MY_LOG_LEVEL_ERROR 5

#define MY_LOG_LEVEL_FATAL 6

#define MY_LOG_LEVEL_SILENT 7

#ifndef MY_LOG_TAG

#    define MY_LOG_TAG __FILE__

#endif

#ifndef MY_LOG_LEVEL

#    define MY_LOG_LEVEL MY_LOG_LEVEL_VERBOSE

#endif

#define MY_LOG_NOOP (void) 0

#define MY_LOG_PRINT(level,fmt,...) \

        __android_log_print(level, MY_LOG_TAG, "(%s:%u) %s: " fmt, \

                __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__)

#if MY_LOG_LEVEL_VERBOSE >= MY_LOG_LEVEL

#    define MY_LOG_VERBOSE(fmt,...) \

        MY_LOG_PRINT(ANDROID_LOG_VERBOSE, fmt, ##__VA_ARGS__)

#else

#    define MY_LOG_VERBOSE(...) MY_LOG_NOOP

#endif

 

#if MY_LOG_LEVEL_DEBUG >= MY_LOG_LEVEL

#    define MY_LOG_DEBUG(fmt,...) \

MY_LOG_PRINT(ANDROID_LOG_DEBUG,fmt, ##__VA_ARGS__)

 #else

#    define MY_LOG_DEBUG(...) MY_LOG_NOOP

#endif

 

#if MY_LOG_LEVEL_INFO >= MY_LOG_LEVEL

#    define MY_LOG_INFO(fmt,...) \

        MY_LOG_PRINT(ANDROID_LOG_INFO, fmt, ##__VA_ARGS__)

#else

#    define MY_LOG_INFO(...) MY_LOG_NOOP

#endif

 

#if MY_LOG_LEVEL_WARNING >= MY_LOG_LEVEL

#    define MY_LOG_WARNING(fmt,...)  \

        MY_LOG_PRINT(ANDROID_LOG_WARN, fmt, ##__VA_ARGS__)

//        MY_LOG_PRINT(ANDROID_LOG_ERROR, fmt, ##__VA_ARGS__)

#    define MY_LOG_FATAL(fmt,...) \

        MY_LOG_PRINT(ANDROID_LOG_FATAL, fmt, ##__VA_ARGS__)

#else

#    define MY_LOG_FATAL(...) MY_LOG_NOOP

#endif

 

#if MY_LOG_LEVEL_FATAL >= MY_LOG_LEVEL

#    define MY_LOG_ASSERT(expression, fmt, ...) \

if (!(expression)) { \

            __android_log_assert(#expression, MY_LOG_TAG, \

                fmt, ##__VA_ARGS__); \

}

#else

#    define MY_LOG_ASSERT(...) MY_LOG_NOOP

#endif

 

/*

 宏替换不是很了解的话可以用gcc -E 命令测试

  这里##如果可变参数长度为0, 会去掉前面的,

  这里的#会把后面的参数当成字符串

  例:

        #define E(expression) a(#expression)

 

        E(1>2) -> a("1>2)

        E("1>2") ->a("1>2")

*/

 

#endif /* MY_LOG_H_ */

 

转载于:https://www.cnblogs.com/zhangyan-2015/p/5647626.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值