diff --git a/DOCS/client-api-changes.rst b/DOCS/client-api-changes.rst index 241b7569d4..54fe585b1b 100644 --- a/DOCS/client-api-changes.rst +++ b/DOCS/client-api-changes.rst @@ -32,6 +32,7 @@ API changes :: + 1.19 - mpv_request_log_messages() now accepts "terminal-default" as parameter 1.18 - add MPV_END_FILE_REASON_REDIRECT, and change behavior of MPV_EVENT_END_FILE accordingly - a bunch of interface-changes.rst changes diff --git a/common/msg.c b/common/msg.c index a2b0cf2169..6a7f699b31 100644 --- a/common/msg.c +++ b/common/msg.c @@ -106,16 +106,12 @@ static void update_loglevel(struct mp_log *log) { struct mp_log_root *root = log->root; pthread_mutex_lock(&mp_msg_lock); - log->level = -1; - log->terminal_level = -1; - if (log->root->use_terminal) { - log->level = MSGL_STATUS + log->root->verbose; // default log level - for (int n = 0; root->msg_levels && root->msg_levels[n * 2 + 0]; n++) { - if (match_mod(log->verbose_prefix, root->msg_levels[n * 2 + 0])) - log->level = mp_msg_find_level(root->msg_levels[n * 2 + 1]); - } - log->terminal_level = log->root->use_terminal ? log->level : -1; + log->level = MSGL_STATUS + log->root->verbose; // default log level + for (int n = 0; root->msg_levels && root->msg_levels[n * 2 + 0]; n++) { + if (match_mod(log->verbose_prefix, root->msg_levels[n * 2 + 0])) + 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); if (log->root->log_file) @@ -239,7 +235,7 @@ static void pretty_print_module(FILE* stream, const char *prefix, bool use_color static bool test_terminal_level(struct mp_log *log, int lev) { - return lev <= log->terminal_level && + return lev <= log->terminal_level && log->root->use_terminal && !(lev == MSGL_STATUS && terminal_in_background()); } @@ -297,7 +293,10 @@ static void write_msg_to_buffers(struct mp_log *log, int lev, char *text) struct mp_log_root *root = log->root; for (int n = 0; n < root->num_buffers; n++) { struct mp_log_buffer *buffer = root->buffers[n]; - if (lev <= buffer->level && lev != MSGL_STATUS) { + int buffer_level = buffer->level; + if (buffer_level == MP_LOG_BUFFER_MSGL_TERM) + buffer_level = log->terminal_level; + if (lev <= buffer_level && lev != MSGL_STATUS) { // Assuming a single writer (serialized by msg lock) int avail = mp_ring_available(buffer->ring) / sizeof(void *); if (avail < 1) diff --git a/common/msg_control.h b/common/msg_control.h index c26a557c9e..d8d9b2e6e9 100644 --- a/common/msg_control.h +++ b/common/msg_control.h @@ -18,6 +18,9 @@ struct mp_log_buffer_entry { char *text; }; +// Use --msg-level option for log level of this log buffer +#define MP_LOG_BUFFER_MSGL_TERM (MSGL_MAX + 1) + struct mp_log_buffer; struct mp_log_buffer *mp_msg_log_buffer_new(struct mpv_global *global, int size, int level, diff --git a/libmpv/client.h b/libmpv/client.h index 3bfced25ca..54ac421209 100644 --- a/libmpv/client.h +++ b/libmpv/client.h @@ -198,7 +198,7 @@ extern "C" { * relational operators (<, >, <=, >=). */ #define MPV_MAKE_VERSION(major, minor) (((major) << 16) | (minor) | 0UL) -#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 18) +#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 19) /** * Return the MPV_CLIENT_API_VERSION the mpv source has been compiled with. @@ -1418,6 +1418,9 @@ int mpv_request_event(mpv_handle *ctx, mpv_event_id event, int enable); * @param min_level Minimal log level as string. Valid log levels: * no fatal error warn info status v debug trace * The value "no" disables all messages. This is the default. + * An exception is the value "terminal-default", which uses the + * log level as set by the "--msg-level" option. This works + * even if the terminal is disabled. (Since API version 1.19.) * Also see mpv_log_level. */ int mpv_request_log_messages(mpv_handle *ctx, const char *min_level); diff --git a/player/client.c b/player/client.c index 71a8f5acbf..a23456510f 100644 --- a/player/client.c +++ b/player/client.c @@ -1523,6 +1523,9 @@ int mpv_request_log_messages(mpv_handle *ctx, const char *min_level) break; } } + if (strcmp(min_level, "terminal-default") == 0) + level = MP_LOG_BUFFER_MSGL_TERM; + if (level < 0 && strcmp(min_level, "no") != 0) return MPV_ERROR_INVALID_PARAMETER;