summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-06-20 21:40:47 +0200
committerwm4 <wm4@nowhere>2015-06-20 21:40:47 +0200
commit23b83c6676c17963a59febeac72fdc73a4198769 (patch)
treeac79ca8400a0a7e2c45819fb71362783bb114462
parent34fce974c60177444d23ab1b658545b32046785f (diff)
downloadmpv-23b83c6676c17963a59febeac72fdc73a4198769.tar.bz2
mpv-23b83c6676c17963a59febeac72fdc73a4198769.tar.xz
client API: allow using msg-level option for log messages
Client API users can enable log output with mpv_request_log_messages(). But you can enable only a single log level. This is normally enough, but the --msg-level option (which controls the terminal log level) provides more flexibility. Due to internal complexity, it would be hard to provide the same flexibility for each client API handle. But there's a simple way to achieve basically the same thing: add an option that sends log messages to the API handle, which would also be printed to the terminal as by --msg-level. The only change is that we don't disable this logic if the terminal is disabled. Instead we check for this before the message is output, which in theory can lower performance if messages are being spammed. It could be handled with some more effort, but the gain would be negligible.
-rw-r--r--DOCS/client-api-changes.rst1
-rw-r--r--common/msg.c21
-rw-r--r--common/msg_control.h3
-rw-r--r--libmpv/client.h5
-rw-r--r--player/client.c3
5 files changed, 21 insertions, 12 deletions
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;