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

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

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 | Categories: Blog |

Share with others

No Responses so far | Have Your Say!

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>