From eba5d025d2ba682de358b792dd15e80529d6a0f1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 21 Dec 2013 21:41:18 +0100 Subject: msg: convert defines to enum Also get rid of MSGL_HINT and the many MSGL_DBG* levels. --- common/av_log.c | 2 +- common/msg.c | 7 ++++--- common/msg.h | 44 ++++++++++++++++++++++---------------------- 3 files changed, 27 insertions(+), 26 deletions(-) (limited to 'common') diff --git a/common/av_log.c b/common/av_log.c index 0ee39b3022..a6d51f88e3 100644 --- a/common/av_log.c +++ b/common/av_log.c @@ -69,7 +69,7 @@ static bool log_print_prefix = true; static int av_log_level_to_mp_level(int av_level) { if (av_level > AV_LOG_VERBOSE) - return MSGL_DBG2; + return MSGL_DEBUG; if (av_level > AV_LOG_INFO) return MSGL_V; if (av_level > AV_LOG_WARNING) diff --git a/common/msg.c b/common/msg.c index 8563cadc65..3a6f3a14e3 100644 --- a/common/msg.c +++ b/common/msg.c @@ -114,6 +114,7 @@ static void update_loglevel(struct mp_log *log) pthread_mutex_unlock(&mp_msg_lock); } +// Return whether the message at this verbosity level would be actually printed. bool mp_msg_test_log(struct mp_log *log, int lev) { if (mp_msg_mute || !log->root) @@ -136,7 +137,7 @@ static int mp_msg_docolor(void) static void set_msg_color(FILE* stream, int lev) { - static const int v_colors[] = {9, 1, 3, 3, -1, -1, 2, 8, 8, 8, 9}; + static const int v_colors[] = {9, 1, 3, -1, -1, 2, 8, 8, -1}; if (mp_msg_docolor()) terminal_set_foreground_color(stream, v_colors[lev]); } @@ -272,8 +273,8 @@ static const char *level_names[] = { [MSGL_INFO] = "info", [MSGL_STATUS] = "status", [MSGL_V] = "v", - [MSGL_DBG2] = "debug", - [MSGL_DBG5] = "trace", + [MSGL_DEBUG] = "debug", + [MSGL_TRACE] = "trace", }; int mp_msg_split_msglevel(struct bstr *s, struct bstr *out_mod, int *out_level) diff --git a/common/msg.h b/common/msg.h index 41fcbbe3e9..fd0e176273 100644 --- a/common/msg.h +++ b/common/msg.h @@ -37,18 +37,17 @@ extern int mp_smode; // slave mode compatibility glue extern struct mp_log *const mp_null_log; // Verbosity levels. -#define MSGL_FATAL 0 // will exit/abort (note: msg.c doesn't exit or abort) -#define MSGL_ERR 1 // continues -#define MSGL_WARN 2 // only warning -#define MSGL_HINT 3 // (to be phased out) -#define MSGL_INFO 4 // -quiet -#define MSGL_STATUS 5 // exclusively for the playback status line -#define MSGL_V 6 // -v -#define MSGL_DBG2 7 // -v -v -#define MSGL_DBG3 8 // ... -#define MSGL_DBG4 9 // .... -#define MSGL_DBG5 10 // ..... -#define MSGL_SMODE 11 // old slave mode (-identify) +enum { + MSGL_FATAL, // will exit/abort (note: msg.c doesn't exit or abort) + MSGL_ERR, // continues + MSGL_WARN, // only warning + MSGL_INFO, // -quiet + MSGL_STATUS, // exclusively for the playback status line + MSGL_V, // -v + MSGL_DEBUG, // -v -v + MSGL_TRACE, // -v -v -v + MSGL_SMODE, // old slave mode (-identify) +}; struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, const char *name); @@ -59,6 +58,15 @@ void mp_msg_log_va(struct mp_log *log, int lev, const char *format, va_list va); bool mp_msg_test_log(struct mp_log *log, int lev); +// Convenience macros. +#define mp_fatal(log, ...) mp_msg_log(log, MSGL_FATAL, __VA_ARGS__) +#define mp_err(log, ...) mp_msg_log(log, MSGL_ERR, __VA_ARGS__) +#define mp_warn(log, ...) mp_msg_log(log, MSGL_WARN, __VA_ARGS__) +#define mp_info(log, ...) mp_msg_log(log, MSGL_INFO, __VA_ARGS__) +#define mp_verbose(log, ...) mp_msg_log(log, MSGL_V, __VA_ARGS__) +#define mp_dbg(log, ...) mp_msg_log(log, MSGL_DEBUG, __VA_ARGS__) +#define mp_trace(log, ...) mp_msg_log(log, MSGL_TRACE, __VA_ARGS__) + // Convenience macros, typically called with a pointer to a context struct // as first argument, which has a "struct mp_log log;" member. @@ -69,18 +77,10 @@ bool mp_msg_test_log(struct mp_log *log, int lev); #define MP_WARN(obj, ...) MP_MSG(obj, MSGL_WARN, __VA_ARGS__) #define MP_INFO(obj, ...) MP_MSG(obj, MSGL_INFO, __VA_ARGS__) #define MP_VERBOSE(obj, ...) MP_MSG(obj, MSGL_V, __VA_ARGS__) -#define MP_DBG(obj, ...) MP_MSG(obj, MSGL_DBG2, __VA_ARGS__) -#define MP_TRACE(obj, ...) MP_MSG(obj, MSGL_DBG5, __VA_ARGS__) +#define MP_DBG(obj, ...) MP_MSG(obj, MSGL_DEBUG, __VA_ARGS__) +#define MP_TRACE(obj, ...) MP_MSG(obj, MSGL_TRACE, __VA_ARGS__) #define MP_SMODE(obj, ...) MP_MSG(obj, MSGL_SMODE, __VA_ARGS__) -#define mp_fatal(log, ...) mp_msg_log(log, MSGL_FATAL, __VA_ARGS__) -#define mp_err(log, ...) mp_msg_log(log, MSGL_ERR, __VA_ARGS__) -#define mp_warn(log, ...) mp_msg_log(log, MSGL_WARN, __VA_ARGS__) -#define mp_info(log, ...) mp_msg_log(log, MSGL_INFO, __VA_ARGS__) -#define mp_verbose(log, ...) mp_msg_log(log, MSGL_V, __VA_ARGS__) -#define mp_dbg(log, ...) mp_msg_log(log, MSGL_DBG2, __VA_ARGS__) -#define mp_trace(log, ...) mp_msg_log(log, MSGL_DBG5, __VA_ARGS__) - struct mpv_global; void mp_msg_init(struct mpv_global *global); void mp_msg_uninit(struct mpv_global *global); -- cgit v1.2.3