12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #include "precompile.h"
- #include "audiolog.h"
- #include <stdlib.h>
- #ifdef _WIN32
- static void __stdcall default_log_func(int level, const char* s)
- #else
- static void __attribute__((__stdcall)) default_log_func(int level, const char* s)
- #endif
- {
- OutputDebugStringA(s);
- }
- static int g_log_level = 0;
- static audio_log_func g_log_func = &default_log_func;
- static int can_log(int level)
- {
- return level >= g_log_level && g_log_func;
- }
- void audio_log_set_level(int level)
- {
- g_log_level = level;
- }
- audio_log_func audio_log_set_func(audio_log_func func)
- {
- audio_log_func old = g_log_func;
- g_log_func = func;
- return old;
- }
- void audio_log(int level, const char *str)
- {
- if (can_log(level)) {
- (*g_log_func)(level, str);
- }
- }
- void audio_log_v(int level, const char *fmt, ...)
- {
- int rc;
- va_list arg;
- if (can_log(level)) {
- va_start(arg, fmt);
- rc = vsnprintf(NULL, 0, fmt, arg);
- if (rc > 0) {
- char *p = malloc(rc + 1);
- if (p) {
- vsprintf(p, fmt, arg);
- audio_log(level, p);
- free(p);
- }
- }
- va_end(arg);
- }
- }
|