client API: introduce numeric log levels

Maybe using strings for log levels was a mistake (too broad and too
impractical), so I'm adding numeric log level at least for the receiver
side. This makes it easier to map mpv log levels to other logging
systems.

I'm still too stingy to add a function to set the log level by a numeric
value, though.

The numeric values are not directly mapped to the internal mpv values,
because then almost every file in mpv would have to include the client
API header.

Coalesce this into API version 1.6, since 1.6 was bumped just yesterday.
This commit is contained in:
wm4 2014-10-08 14:15:14 +02:00
parent ab5d58c3d9
commit 0ec5d35d57
5 changed files with 41 additions and 1 deletions

View File

@ -27,6 +27,7 @@ API changes
1.6 - modify "core-idle" property behavior
- MPV_EVENT_LOG_MESSAGE now always sends complete lines
- introduce numeric log levels (mpv_log_level)
--- mpv 0.6.0 is released ---
1.5 - change in X11 and "--wid" behavior again. The previous change didn't
work as expected, and now the behavior can be explicitly controlled

View File

@ -37,6 +37,8 @@
#include "osdep/io.h"
#include "osdep/timer.h"
#include "libmpv/client.h"
#include "msg.h"
#include "msg_control.h"
@ -600,6 +602,18 @@ const char *const mp_log_levels[MSGL_MAX + 1] = {
[MSGL_STATS] = "stats",
};
const int const mp_mpv_log_levels[MSGL_MAX + 1] = {
[MSGL_FATAL] = MPV_LOG_LEVEL_FATAL,
[MSGL_ERR] = MPV_LOG_LEVEL_ERROR,
[MSGL_WARN] = MPV_LOG_LEVEL_WARN,
[MSGL_INFO] = MPV_LOG_LEVEL_INFO,
[MSGL_STATUS] = 0, // never used
[MSGL_V] = MPV_LOG_LEVEL_V,
[MSGL_DEBUG] = MPV_LOG_LEVEL_DEBUG,
[MSGL_TRACE] = MPV_LOG_LEVEL_TRACE,
[MSGL_STATS] = 0, // never used
};
int mp_msg_split_msglevel(struct bstr *s, struct bstr *out_mod, int *out_level)
{
if (s->len == 0)

View File

@ -32,5 +32,6 @@ struct bstr;
int mp_msg_split_msglevel(struct bstr *s, struct bstr *out_mod, int *out_level);
extern const char *const mp_log_levels[MSGL_MAX + 1];
extern const int const mp_mpv_log_levels[MSGL_MAX + 1];
#endif

View File

@ -1030,6 +1030,23 @@ typedef struct mpv_event_property {
void *data;
} mpv_event_property;
/**
* Numeric log levels. The lower the number, the more important the message is.
* MPV_LOG_LEVEL_NONE is never used when receiving messages. The string in
* the comment after the value is the name of the log level as used for the
* mpv_request_log_messages() function.
*/
typedef enum mpv_log_level {
MPV_LOG_LEVEL_NONE = 0, /// "no" - disable absolutely all messages
MPV_LOG_LEVEL_FATAL = 10, /// "fatal" - critical/aborting errors
MPV_LOG_LEVEL_ERROR = 20, /// "error" - simple errors
MPV_LOG_LEVEL_WARN = 30, /// "warn" - possible problems
MPV_LOG_LEVEL_INFO = 40, /// "info" - informational message
MPV_LOG_LEVEL_V = 50, /// "v" - noisy informational message
MPV_LOG_LEVEL_DEBUG = 60, /// "debug" - very noisy technical information
MPV_LOG_LEVEL_TRACE = 70, /// "trace" - extremely noisy
} mpv_log_level;
typedef struct mpv_event_log_message {
/**
* The module prefix, identifies the sender of the message. As a special
@ -1040,7 +1057,7 @@ typedef struct mpv_event_log_message {
const char *prefix;
/**
* The log level as string. See mpv_request_log_messages() for possible
* values.
* values. The level "no" is never used here.
*/
const char *level;
/**
@ -1049,6 +1066,11 @@ typedef struct mpv_event_log_message {
* or partial lines.)
*/
const char *text;
/**
* The same contents as the level field, but as a numeric ID.
* Since API version 1.6.
*/
mpv_log_level log_level;
} mpv_event_log_message;
typedef struct mpv_event_end_file {
@ -1146,6 +1168,7 @@ 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.
* Also see mpv_log_level.
*/
int mpv_request_log_messages(mpv_handle *ctx, const char *min_level);

View File

@ -654,6 +654,7 @@ mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout)
*cmsg = (struct mpv_event_log_message){
.prefix = talloc_steal(event, msg->prefix),
.level = mp_log_levels[msg->level],
.log_level = mp_mpv_log_levels[msg->level],
.text = talloc_steal(event, msg->text),
};
event->data = cmsg;