Skip to content

Commit

Permalink
Update logging behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
bozbez committed Feb 12, 2022
1 parent bb3444c commit be2eb88
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,19 @@
#include <obs.h>

#define do_log(level, format, ...) \
do_log_source(level, "(%s) " format, __func__, ##__VA_ARGS__)
do_log_source(level, "[win-capture-audio] (%s) " format, __func__, ##__VA_ARGS__)

inline static void do_log_source(int level, const char *format, ...)
{
va_list args;
va_start(args, format);

blogva(level, format, args);

const char *name = "unknown";
int len = strlen(name);

const char *format_source = len <= 8 ? "[audio-capture: '%s'] %s"
: "[audio-capture: '%.8s...'] %s";

int len_full = strlen(format_source) + 12 + strlen(format);
char *format_full = (char *)bzalloc(len_full);

snprintf(format_full, len_full, format_source, name, format);
blogva(level, format_full, args);

bfree(format_full);
va_end(args);
}

#define error(format, ...) do_log(LOG_ERROR, format, ##__VA_ARGS__)
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)

0 comments on commit be2eb88

Please sign in to comment.