add timestamps to jni logs

This commit is contained in:
Andy2 2011-07-04 09:38:22 -07:00 committed by Andy2
parent d76ca5938b
commit 82552e681a
2 changed files with 34 additions and 3 deletions

View file

@ -18,6 +18,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <sys/time.h>
#include <time.h>
#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 ) */

View file

@ -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(...)