您的位置:首页 > 移动开发 > Android开发

Simple Logging for Android & iPhone

2014-01-11 23:56 405 查看
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(..).

[code]#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.

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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐