mirror of https://github.com/mpv-player/mpv
msg: convert defines to enum
Also get rid of MSGL_HINT and the many MSGL_DBG* levels.
This commit is contained in:
parent
3fa584e280
commit
eba5d025d2
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
44
common/msg.h
44
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);
|
||||
|
|
|
@ -698,7 +698,7 @@ int ebml_read_element(struct stream *s, struct ebml_parse_ctx *ctx,
|
|||
void *target, const struct ebml_elem_desc *desc)
|
||||
{
|
||||
ctx->has_errors = false;
|
||||
int msglevel = ctx->no_error_messages ? MSGL_DBG2 : MSGL_WARN;
|
||||
int msglevel = ctx->no_error_messages ? MSGL_DEBUG : MSGL_WARN;
|
||||
uint64_t length = ebml_read_length(s, &ctx->bytes_read);
|
||||
if (s->eof) {
|
||||
MP_MSG(ctx, msglevel, "Unexpected end of file "
|
||||
|
|
|
@ -1455,7 +1455,7 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, char *force_section,
|
|||
int msgl = MSGL_WARN;
|
||||
if (n == 1 && (keys[0] == MP_KEY_MOUSE_MOVE ||
|
||||
keys[0] == MP_KEY_MOUSE_LEAVE))
|
||||
msgl = MSGL_DBG2;
|
||||
msgl = MSGL_DEBUG;
|
||||
char *key_buf = get_key_combo_name(keys, n);
|
||||
MP_MSG(ictx, msgl, "No bind found for key '%s'.\n", key_buf);
|
||||
talloc_free(key_buf);
|
||||
|
@ -1464,7 +1464,7 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, char *force_section,
|
|||
mp_cmd_t *ret = mp_input_parse_cmd(ictx, bstr0(cmd->cmd), cmd->location);
|
||||
if (ret) {
|
||||
ret->input_section = cmd->owner->section;
|
||||
if (mp_msg_test_log(ictx->log, MSGL_DBG2)) {
|
||||
if (mp_msg_test_log(ictx->log, MSGL_DEBUG)) {
|
||||
char *keyname = get_key_combo_name(keys, n);
|
||||
MP_DBG(ictx, "key '%s' -> '%s' in '%s'\n",
|
||||
keyname, cmd->cmd, ret->input_section);
|
||||
|
@ -1578,7 +1578,7 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale)
|
|||
if (unmod >= 32 && unmod < MP_KEY_BASE)
|
||||
code &= ~MP_KEY_MODIFIER_SHIFT;
|
||||
|
||||
if (mp_msg_test_log(ictx->log, MSGL_DBG2)) {
|
||||
if (mp_msg_test_log(ictx->log, MSGL_DEBUG)) {
|
||||
int noflags = code & ~(MP_KEY_STATE_DOWN | MP_KEY_STATE_UP);
|
||||
char *key = get_key_name(noflags, NULL);
|
||||
MP_DBG(ictx, "key code=%#x '%s'%s%s\n",
|
||||
|
|
|
@ -260,7 +260,7 @@ static const char *log_level[] = {
|
|||
[MSGL_WARN] = "warn",
|
||||
[MSGL_INFO] = "info",
|
||||
[MSGL_V] = "verbose",
|
||||
[MSGL_DBG2] = "debug",
|
||||
[MSGL_DEBUG] = "debug",
|
||||
};
|
||||
|
||||
static int script_log(lua_State *L)
|
||||
|
|
|
@ -209,8 +209,8 @@ static int map_ass_level[] = {
|
|||
MSGL_V,
|
||||
MSGL_V,
|
||||
MSGL_V, // 5 application recommended level
|
||||
MSGL_DBG2,
|
||||
MSGL_DBG3, // 7 "verbose DEBUG"
|
||||
MSGL_DEBUG,
|
||||
MSGL_TRACE, // 7 "verbose DEBUG"
|
||||
};
|
||||
|
||||
static void message_callback(int level, const char *format, va_list va, void *ctx)
|
||||
|
|
|
@ -549,7 +549,7 @@ void mpgl_load_functions(GL *gl, void *(*getProcAddress)(const GLubyte *),
|
|||
|
||||
if (has_legacy)
|
||||
mp_msg_log(log, MSGL_V, "OpenGL legacy compat. found.\n");
|
||||
mp_msg_log(log, MSGL_DBG2, "Combined OpenGL extensions string:\n%s\n",
|
||||
mp_msg_log(log, MSGL_DEBUG, "Combined OpenGL extensions string:\n%s\n",
|
||||
gl->extensions);
|
||||
|
||||
for (int n = 0; n < sizeof(gl_functions) / sizeof(gl_functions[0]); n++) {
|
||||
|
|
|
@ -691,7 +691,7 @@ static GLuint create_shader(struct gl_video *p, GLenum type, const char *header,
|
|||
GLint log_length;
|
||||
gl->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length);
|
||||
|
||||
int pri = status ? (log_length > 1 ? MSGL_V : MSGL_DBG2) : MSGL_ERR;
|
||||
int pri = status ? (log_length > 1 ? MSGL_V : MSGL_DEBUG) : MSGL_ERR;
|
||||
const char *typestr = type == GL_VERTEX_SHADER ? "vertex" : "fragment";
|
||||
if (mp_msg_test_log(p->log, pri)) {
|
||||
MP_MSG(p, pri, "%s shader source:\n", typestr);
|
||||
|
@ -727,7 +727,7 @@ static void link_shader(struct gl_video *p, GLuint program)
|
|||
GLint log_length;
|
||||
gl->GetProgramiv(program, GL_INFO_LOG_LENGTH, &log_length);
|
||||
|
||||
int pri = status ? (log_length > 1 ? MSGL_V : MSGL_DBG2) : MSGL_ERR;
|
||||
int pri = status ? (log_length > 1 ? MSGL_V : MSGL_DEBUG) : MSGL_ERR;
|
||||
if (mp_msg_test_log(p->log, pri)) {
|
||||
GLchar *logstr = talloc_zero_size(NULL, log_length + 1);
|
||||
gl->GetProgramInfoLog(program, log_length, NULL, logstr);
|
||||
|
|
Loading…
Reference in New Issue