1. android/log.h
In ndk library provide log functions that can be seen in LogCat. First you have to include <android/log.h>.
#include <android/log.h>
You can use two functions [__android_log_write] and [__android_log_vprint]. If you want to write log like printf, Use [__android_log_vprint]. It support parameters like %d, %f, %s.etc else [__android_log_write] only send a message. Below show example using [__android_log_write] and [__android_log_vprint]
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, msg.c_str()); __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, msg.c_str(), ap);
2. Tag
Android Log have tags
ANDROID_LOG_UNKNOWN ,
ANDROID_LOG_DEFAULT,
ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG,
ANDROID_LOG_INFO,
ANDROID_LOG_WARN,
ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL,
ANDROID_LOG_SILENT.
we usually use INFO, WARN, ERROR, VERBOSE. DEBUG. LogCat in eclipse IDE show you message according to each tag.
3. Wrapping
I recommend wrapping log functions for more clear and useful.
class Log { public: static void info(string msg) { #if defined(LOG) && !defined(PUBLISH) __android_log_write(ANDROID_LOG_INFO, LOG_TAG, msg.c_str()); #endif } static void info_print(string msg, ...) { #if defined(LOG) && !defined(PUBLISH) va_list ap; va_start(ap,msg); __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, msg.c_str(), ap); va_end(ap); #endif } static void debug(string msg) { #if defined(LOG) && !defined(PUBLISH) __android_log_write(ANDROID_LOG_DEBUG, LOG_TAG, msg.c_str()); #endif } static void debug_print(string msg, ...) { #if defined(LOG) && !defined(PUBLISH) va_list ap; va_start(ap,msg); __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, msg.c_str(), ap); va_end(ap); #endif } static void warning(string msg) { #if defined(LOG) && !defined(PUBLISH) __android_log_write(ANDROID_LOG_WARN, LOG_TAG, msg.c_str()); #endif } static void warning_print(string msg, ...) { #if defined(LOG) && !defined(PUBLISH) va_list ap; va_start(ap,msg); __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, msg.c_str(), ap); va_end(ap); #endif } static void error(string msg) { #if defined(LOG) && !defined(PUBLISH) __android_log_write(ANDROID_LOG_ERROR, LOG_TAG, msg.c_str()); #endif } static void error_print(string msg, ...) { #if defined(LOG) && !defined(PUBLISH) va_list ap; va_start(ap,msg); __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, msg.c_str(), ap); va_end(ap); #endif } };
I made 4 kind methods using tags is ERROR, WARN, INFO and DEBUG, and if publish mode, I don't write a log to improve performance. I used this methods like below code.
Log::info_print("GL_EXTENSIONS : %s",glGetString(GL_EXTENSIONS)); Log::info_print("GL_VENDOR : %s",glGetString(GL_VENDOR)); Log::info_print("GL_RENDERER : %s",glGetString(GL_RENDERER)); Log::info_print("GL_VERSION : %s",glGetString(GL_VERSION)); Log::info("GLManager::jdGLInit end");
In OpenGL Dirary app, you can see this logs.
'게임을 만들자 > NDK & OpenGL ES' 카테고리의 다른 글
Android ndk, unicode to utf-8 or utf-8 to unicode (0) | 2015.01.07 |
---|---|
Android, Draw text using system font OpenGLES 2.0 (0) | 2014.09.24 |
Android, NDK OpenGLES2.0 Texture (0) | 2014.09.22 |
OpenGLES2.0 GLSL, 2D Basic shader (1) | 2014.09.18 |
OpenGLES 2.0,GLSL lighting code (0) | 2014.09.15 |