From 7024718c87d3c205a16fbe3586ba07afc703b902 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 4 Jul 2011 09:38:22 -0700 Subject: [PATCH] add timestamps to jni logs --- xwords4/android/XWords4/jni/andutils.c | 30 ++++++++++++++++++++++++++ xwords4/android/XWords4/jni/xptypes.h | 7 +++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/jni/andutils.c b/xwords4/android/XWords4/jni/andutils.c index 9489e623c..a10044c81 100644 --- a/xwords4/android/XWords4/jni/andutils.c +++ b/xwords4/android/XWords4/jni/andutils.c @@ -18,6 +18,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include +#include + #include "andutils.h" #include "comtypes.h" @@ -466,6 +469,33 @@ and_empty_stream( MPFORMAL AndGlobals* globals ) return stream; } +#ifdef DEBUG +void +android_debugf( const char* format, ... ) +{ + char buf[1024]; + va_list ap; + int len; + struct tm* timp; + struct timeval tv; + struct timezone tz; + + gettimeofday( &tv, &tz ); + timp = localtime( &tv.tv_sec ); + + len = snprintf( buf, sizeof(buf), "%.2d:%.2d:%.2d: ", + timp->tm_hour, timp->tm_min, timp->tm_sec ); + if ( len < sizeof(buf) ) { + va_start(ap, format); + vsnprintf( buf + len, sizeof(buf)-len, format, ap ); + va_end(ap); + } + + (void)__android_log_write( ANDROID_LOG_DEBUG, "xw4", buf ); +} +#endif + + /* #ifdef DEBUG */ /* XP_U32 */ /* andy_rand( const char* caller ) */ diff --git a/xwords4/android/XWords4/jni/xptypes.h b/xwords4/android/XWords4/jni/xptypes.h index b1d76d1b4..b0f3c3922 100644 --- a/xwords4/android/XWords4/jni/xptypes.h +++ b/xwords4/android/XWords4/jni/xptypes.h @@ -88,9 +88,10 @@ void and_assert( const char* test, int line, const char* file, const char* func #define XP_STATUSF XP_DEBUGF #ifdef ENABLE_LOGGING -#define XP_DEBUGF(...) __android_log_print( ANDROID_LOG_DEBUG, "tag", __VA_ARGS__) -#define XP_LOGF(...) __android_log_print( ANDROID_LOG_DEBUG, "tag", __VA_ARGS__) -#define XP_WARNF(...) __android_log_print( ANDROID_LOG_DEBUG, "tag", __VA_ARGS__) +void android_debugf(const char*, ...) __attribute__ ((format (printf, 1, 2))); +#define XP_DEBUGF(...) android_debugf( __VA_ARGS__ ) +#define XP_LOGF(...) android_debugf( __VA_ARGS__ ) +#define XP_WARNF(...) android_debugf( __VA_ARGS__ ) #else #define XP_DEBUGF(...) #define XP_LOGF(...)