Simple Logging for Android & iPhone

本文提供了一种适用于Android和iOS设备的简易日志记录宏,旨在简化错误追踪并提升开发者效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Simple Logging for Android & iPhone

http://codingincircles.com/2010/12/simple-logging-for-android-iphone/

Dec 18, 2010
Logging is one of those things I don’t want to implement until I get an error somewhere and I’d rather not try to track it down with a debugger. This happens very quickly when dealing with XCode’s included and rather lacking debugger, or on Android’s command-line-only native code debugger.
So, for my and public domain usage: A simple logging macro


Source code   
#ifndef REMOVE_LOGGING
#ifdef ANDROID
#define LOG_DEBUG(message, ...) \
    do { __android_log_print(ANDROID_LOG_DEBUG, "Terrasweeper", "[%s:%d] " message, __FILE__, __LINE__, ##__VA_ARGS__); } while (0)
#else
#define LOG_DEBUG(message, ...) \
    do { std::printf("[%s:%d] " message "\n", __FILE__, __LINE__,  ##__VA_ARGS__); } while(0)
#endif
#else
#define LOG_DEBUG(message, ...) do { LOG_UNUSED(message); } while (0)
#endif


As you can see, it supports Windows, Unix and iPhone through stdout, and android through the custom logging that you can retrieve with the LogCat tool

Posted by Tatham | Categories: Blog |



Log to logcat.

1) To invoke the logger in native code include the header and call _android_log_write(..).

#include <android/log.h>

__android_log_write(ANDROID_LOG_INFO, "tag here", "message here");

2) In your Android.mk file include the log lib like this.

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值