From 5d9aa72f25a1193f6406d8ecda92c8a2142923ef Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 16 Dec 2019 21:31:54 +0100 Subject: msg: fix "terminal-default" logging mode console.lua uses "terminal-default" logging, which is supposed to return all messages logged to the terminal to the API. Internally, this is translated to MP_LOG_BUFFER_MSGL_TERM, which is MSGL_MAX+1, because it's not an actual log level (blame C for not having proper sum types or something). Unfortunately, this unintentionally raised the internal log level to MSGL_MAX+1. It still functioned as intended, because log messages were simply filtered at a "later" point. But it led to every message being formatted even if not needed. More importantly, it made mp_msg_test() pointless (code calls this to avoid logging in "expensive" cases and if the messages would just get discarded). Also, this broke libplacebo logging, because the code to map the log messages did not expect a level higher than MSGL_MAX (mp_msg_level() returned MSGL_MAX+1 too). Fix this by not letting the dummy level value be used as log level. Messages at terminal log level will always make it to the inner log message dispatcher function (i.e. mp_msg_va() will call write_msg_to_buffers()), so log buffers which use the dummy log level don't need to adjust the actual log level at all. --- common/msg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/msg.c b/common/msg.c index 2756a27e8d..ca90bcaba5 100644 --- a/common/msg.c +++ b/common/msg.c @@ -123,8 +123,11 @@ static void update_loglevel(struct mp_log *log) log->level = mp_msg_find_level(root->msg_levels[n * 2 + 1]); } log->terminal_level = log->level; - for (int n = 0; n < log->root->num_buffers; n++) - log->level = MPMAX(log->level, log->root->buffers[n]->level); + for (int n = 0; n < log->root->num_buffers; n++) { + int buffer_level = log->root->buffers[n]->level; + if (buffer_level != MP_LOG_BUFFER_MSGL_TERM) + log->level = MPMAX(log->level, buffer_level); + } if (log->root->log_file) log->level = MPMAX(log->level, MSGL_DEBUG); if (log->root->stats_file) -- cgit v1.2.3