45 static void (*ni_log_callback)(int,
const char*,
va_list) =
49 static ni_pthread_mutex_t ni_log2_mutex;
50 static int ni_log2_mutex_initialized = 0;
51 INIT_ONCE g_InitOnce_ni_log2_mutex = INIT_ONCE_STATIC_INIT;
53 static ni_pthread_mutex_t ni_log2_mutex = PTHREAD_MUTEX_INITIALIZER;
56 static int ni_log2_print_with_mutex = 0;
58 #define NI_LOG2_SESSION_ID_TIMESTAMP_FMT "[SID=%x, TS=" "%" PRIu64 "]"
59 #define NI_LOG2_TIMESTAMP_FMT "[TS=" "%" PRIu64 "]"
60 #define NI_LOG2_SESSION_ID_FMT "[SID=%x]"
61 #define NI_LOG2_E2EID_FMT "|%s|"
62 #define NI_LOG2_FMT_FMT "%s"
63 #define NI_LOG2_SPACE " "
65 #define NI_LOG2_PRINT_BUFF_SIZE 512
68 #include <android/log.h>
70 static char ni_log_tag[128] =
"libxcoder";
72 #define ALOGV(fmt, ...) \
73 __android_log_vprint(ANDROID_LOG_VERBOSE, ni_log_tag, fmt, ##__VA_ARGS__)
74 #define ALOGD(fmt, ...) \
75 __android_log_vprint(ANDROID_LOG_DEBUG, ni_log_tag, fmt, ##__VA_ARGS__)
76 #define ALOGI(fmt, ...) \
77 __android_log_vprint(ANDROID_LOG_INFO, ni_log_tag, fmt, ##__VA_ARGS__)
78 #define ALOGW(fmt, ...) \
79 __android_log_vprint(ANDROID_LOG_WARN, ni_log_tag, fmt, ##__VA_ARGS__)
80 #define ALOGE(fmt, ...) \
81 __android_log_vprint(ANDROID_LOG_ERROR, ni_log_tag, fmt, ##__VA_ARGS__)
97 SYSTEMTIME system_time;
98 ULARGE_INTEGER ularge;
100 static const unsigned __int64 epoch =
101 ((
unsigned __int64)116444736000000000ULL);
107 GetSystemTime(&system_time);
108 SystemTimeToFileTime(&system_time, &file_time);
109 ularge.LowPart = file_time.dwLowDateTime;
110 ularge.HighPart = file_time.dwHighDateTime;
112 (void)ularge.LowPart;
113 (
void)ularge.HighPart;
114 p_tp->tv_sec = (long)((ularge.QuadPart - epoch) / 10000000L);
115 p_tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
119 return gettimeofday(p_tp, p_tzp);
136 if (level <= ni_log_level)
139 #ifdef NI_LOG_TRACE_TIMESTAMPS
144 fprintf(stderr,
"[%" PRIu64
"] ", (uint64_t) (tv.tv_sec * 1000000LL + tv.tv_usec));
157 vfprintf(stderr, fmt, vl);
171 ni_log_callback = log_callback;
190 ni_log_callback(level, fmt, vl);
204 ni_log_level = level;
227 if (fflog_level <= -8)
231 else if (fflog_level <= 8)
235 else if (fflog_level <= 16)
239 else if (fflog_level <= 32)
243 else if (fflog_level <= 48)
251 return converted_ni_log_level;
265 int (*strcicmp) (
const char*,
const char *) = &_stricmp;
267 int (*strcicmp) (
const char*,
const char *) = &strcasecmp;
270 if (!(*strcicmp)(arg_str,
"none"))
273 }
else if (!(*strcicmp)(arg_str,
"fatal"))
276 }
else if (!(*strcicmp)(arg_str,
"error"))
279 }
else if (!(*strcicmp)(arg_str,
"info"))
282 }
else if (!(*strcicmp)(arg_str,
"debug"))
285 }
else if (!(*strcicmp)(arg_str,
"trace"))
301 void ni_log_set_log_tag(
const char *log_tag)
303 strcpy(ni_log_tag, log_tag);
304 ni_log_tag[strlen(log_tag)] =
'\0';
312 return (uint64_t) (tv.tv_sec * 1000000LL + tv.tv_usec);
316 static BOOL CALLBACK ni_log2_init_mutex_once_callback(PINIT_ONCE InitOnce,
321 ni_log2_mutex_initialized = 1;
329 if(!ni_log2_mutex_initialized && on)
331 InitOnceExecuteOnce(&g_InitOnce_ni_log2_mutex, ni_log2_init_mutex_once_callback, NULL, NULL);
334 ni_log2_print_with_mutex = on;
341 if(level > ni_log_level)
346 if(ni_log2_print_with_mutex)
355 else if(p_session_context)
370 ni_log_callback(level, fmt, vl);
384 ni_log_callback(level, fmt, vl);
394 int this_used_size = 0;
402 else if(p_session_context)
415 if(this_used_size < 0)
423 ni_log_callback(level, fmt, vl);
438 ni_log_callback(level, fmt, vl);
449 ni_log_callback(level, printbuf, vl);