1 #include "tbm_emulator_log.h"
10 static const char *g_log_level_to_str[] =
18 static pthread_once_t g_log_init = PTHREAD_ONCE_INIT;
19 static int g_debug_enabled = 0;
21 static void tbm_emulator_log_init_once(void)
23 char *debug_enabled_str = getenv("TBM_EMULATOR_DEBUG");
24 g_debug_enabled = debug_enabled_str ? atoi(debug_enabled_str) : 0;
27 static void tbm_emulator_log_init(void)
29 pthread_once(&g_log_init, tbm_emulator_log_init_once);
32 static void tbm_emulator_log_print_current_time(void)
36 struct timeval tv = { 0, 0 };
39 gettimeofday(&tv, NULL);
43 localtime_r(&ti, &tm);
44 strftime(buff, sizeof(buff),
46 fprintf(stderr, "%s", buff);
49 void tbm_emulator_log_event(tbm_emulator_log_level log_level,
52 const char *format, ...)
56 tbm_emulator_log_init();
58 tbm_emulator_log_print_current_time();
61 g_log_level_to_str[log_level],
66 va_start(args, format);
67 fprintf(stderr, " - ");
68 vfprintf(stderr, format, args);
71 fprintf(stderr, "\n");
74 int tbm_emulator_log_is_debug_enabled()
76 tbm_emulator_log_init();
78 return g_debug_enabled;