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 |
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 |
相关文章推荐
- Archive for required library: '/libs/android-support-v4.jar' in project '' cannot be read or is not
- iPhone Tabs for Android!
- 【游戏开发备注之一】关于Cocos2dx_v1.x版本iphone与Android运行出现图片白块、添加GameCenter报错问题及编译Android闪退的解决办法&&CCLOG与CClog的区别
- 『转』Kaspersky Internet Security for Android &KMS – 免费6个月
- Android出错问题:AndroidManifest.xml:2: error: No resource identifier found for attribute 'installLocatio
- Simple&nbsp;guide&nbsp;for&nbsp;Automake/Autoco…
- android Error:Execution failed for task ':app:mergeDebugResources'. > Some file crunching failed, se
- [Android] "Failed to find Java version for 'C:\Windows\system32\java.exe"问题的解决方法
- android build path contains duplicate entry:'src' for project XXX
- 思考:苹果联合创始人史蒂夫·沃兹尼亚克的言论:Android一些地方比iPhone好
- android导入工程时style出错Error retrieving parent for item: No resource found that matches the given name '
- Error:Timeout waiting to lock cp_proj class cache for build file 'D:\androidw\TuYeLiangPin\app\bui
- Android 开发中遇到的Error:Execution failed for task ': :dexDebug'. > com.android.ide.common.process.Proces
- WebKit – WebKit For Android
- Android XML解析(Simple API for XML(SAX) )
- android解析xml文件的SAX方式:Simple API for XML
- Android Starting emulator for AVD 'du'
- Error:Execution failed for task ':myapp:dexDebug'. com.android.ide.common.process.ProcessException:
- android Activity android:launchMode="singleInstance" 与 startActivityForResult
- "Selenium for Android"的Robotium 一 概述