improved debugging usability for all platforms
This commit is contained in:
126
src/SDK_Debug.h
126
src/SDK_Debug.h
@@ -26,33 +26,129 @@
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SDK_DEBUG_H_
|
||||
#define _SDK_DEBUG_H_
|
||||
|
||||
#define DEBUG_LEVEL 4 // Set this to adjust what you'd like to see in the debug traces
|
||||
|
||||
#define MSG_ERROR 1 // Errors
|
||||
#define MSG_TRANSFER 2 // RX/TX specific statements
|
||||
#define MSG_INFO 3 // Information which is generally useful to any user
|
||||
#define MSG_DEBUG 4 // Information which is only useful to someone debugging
|
||||
#define MSG_DEBUG_EXTRA 5 // If nothing in your world makes sense
|
||||
#define MSG_INFO 3 // Information which is generally useful to any developer
|
||||
#define MSG_EXTRA 4 // If nothing in your world makes sense
|
||||
|
||||
extern char *debug_logfile;
|
||||
#define __SHOW_FILENAMES__ true
|
||||
|
||||
// filenames
|
||||
#if __SHOW_FILENAMES__
|
||||
#if __SHOW_FULL_FILENAME_PATH__
|
||||
#define __FILENAME__ __FILE__ // show the entire mess
|
||||
#else
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // shorten
|
||||
#endif
|
||||
#else
|
||||
#define __FILENAME__ // omit filename
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if __ANDROID__
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG "ZTSDK"
|
||||
#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
|
||||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
//#if defined(SDK_DEBUG)
|
||||
#if DEBUG_LEVEL >= MSG_ERROR
|
||||
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, "\nZT_ERROR: %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#else
|
||||
#define DEBUG_ERROR(fmt, args...)
|
||||
#endif
|
||||
#if DEBUG_LEVEL >= MSG_INFO
|
||||
#if defined(__ANDROID__)
|
||||
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "\nZT_INFO : %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
#else
|
||||
#define LOGV(...) fprintf(stdout, __VA_ARGS__)
|
||||
#define LOGI(...) fprintf(stdout, __VA_ARGS__)
|
||||
#define LOGD(...) fprintf(stdout, __VA_ARGS__)
|
||||
#define LOGE(...) fprintf(stdout, __VA_ARGS__)
|
||||
#define DEBUG_INFO(fmt, args...) fprintf(stderr, "\nZT_INFO : %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_BLANK(fmt, args...) fprintf(stderr, "\nZT_INFO : %s:%d:" fmt "\n", __FILENAME__, __LINE__, ##args)
|
||||
#endif
|
||||
#else
|
||||
#define DEBUG_INFO(fmt, args...)
|
||||
#define DEBUG_BLANK(fmt, args...)
|
||||
#endif
|
||||
#if DEBUG_LEVEL >= MSG_TRANSFER
|
||||
#if defined(__ANDROID__)
|
||||
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "\nZT_TRANS : %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
#else
|
||||
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, "\nZT_TRANS: %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#endif
|
||||
#else
|
||||
#define DEBUG_TRANS(fmt, args...)
|
||||
#endif
|
||||
#if DEBUG_LEVEL >= MSG_EXTRA
|
||||
#if defined(__ANDROID__)
|
||||
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "\nZT_EXTRA : %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
#else
|
||||
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, "\nZT_EXTRA: %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#endif
|
||||
#else
|
||||
#define DEBUG_EXTRA(fmt, args...)
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // _SDK_DEBUG_H_
|
||||
|
||||
|
||||
/*
|
||||
void dwr(int level, const char *fmt, ... )
|
||||
{
|
||||
#if defined(SDK_DEBUG)
|
||||
if(level > DEBUG_LEVEL)
|
||||
return;
|
||||
int saveerr;
|
||||
saveerr = errno;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
char timestring[20];
|
||||
time_t timestamp;
|
||||
timestamp = time(NULL);
|
||||
strftime(timestring, sizeof(timestring), "%H:%M:%S", localtime(×tamp));
|
||||
#if defined(__ANDROID__)
|
||||
pid_t tid = gettid();
|
||||
#elif defined(__linux__)
|
||||
pid_t tid = 5;//syscall(SYS_gettid);
|
||||
#elif defined(__APPLE__)
|
||||
pid_t tid = pthread_mach_thread_np(pthread_self());
|
||||
#endif
|
||||
#if defined(SDK_DEBUG_LOG_TO_FILE)
|
||||
if(!debug_logfile) { // Try to get logfile from env
|
||||
debug_logfile = getenv("ZT_SDK_LOGFILE");
|
||||
}
|
||||
if(debug_logfile) {
|
||||
FILE *file = fopen(debug_logfile,"a");
|
||||
fprintf(file, "%s [tid=%7d] ", timestring, tid);
|
||||
vfprintf(file, fmt, ap);
|
||||
fclose(file);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "%s [tid=%7d] ", timestring, tid);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
|
||||
// Outputs to Android debug console
|
||||
#if defined(__ANDROID__)
|
||||
__android_log_vprint(ANDROID_LOG_VERBOSE, "ZT-JNI", fmt, ap);
|
||||
#endif
|
||||
|
||||
fflush(stderr);
|
||||
errno = saveerr;
|
||||
va_end(ap);
|
||||
#endif // _SDK_DEBUG
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user