123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "precompile.h"
- #include "audiolog.h"
- #include <stdlib.h>
- static void __stdcall default_log_func(int level, const char *s)
- {
- 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 = _vscprintf(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);
- }
- }
|