From: RĂ©mi Denis-Courmont Date: Wed, 20 Mar 2013 17:18:59 +0000 (+0200) Subject: libvlc: add functions to query log message "item" data X-Git-Tag: 2.1.0-git~985 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=dac9ab984c7a2017780cae79b8642892514b63c9;p=vlc libvlc: add functions to query log message "item" data Also make provisions for file name and line number in the future. --- diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h index 71f9a6b604..ab1030dad1 100644 --- a/include/vlc/libvlc.h +++ b/include/vlc/libvlc.h @@ -338,6 +338,49 @@ enum libvlc_log_level typedef struct vlc_log_t libvlc_log_t; +/** + * Gets debugging informations about a log message: the name of the VLC module + * emitting the message and the message location within the source code. + * + * The returned module name and file name will be NULL if unknown. + * The returned line number will similarly be zero if unknown. + * + * \param ctx message context (as passed to the @ref libvlc_log_cb callback) + * \param module module name storage (or NULL) [OUT] + * \param file source code file name storage (or NULL) [OUT] + * \param line source code file line number storage (or NULL) [OUT] + * \warning The returned module name and source code file name, if non-NULL, + * are only valid until the logging callback returns. + * + * \version LibVLC 2.1.0 or later + */ +void libvlc_log_get_context(const libvlc_log_t *ctx, const char **module, + const char **file, unsigned *restrict line); + +/** + * Gets VLC object informations about a log message: the type name of the VLC + * object emitting the message, the object header if any and a temporaly-unique + * object identifier. These informations are mainly meant for manual + * troubleshooting. + * + * The returned type name may be "generic" if unknown, but it cannot be NULL. + * The returned header will be NULL if unset; in current versions, the header + * is used to distinguish for VLM inputs. + * The returned object ID will be zero if the message is not associated with + * any VLC object. + * + * \param ctx message context (as passed to the @ref libvlc_log_cb callback) + * \param name object name storage (or NULL) [OUT] + * \param header object header (or NULL) [OUT] + * \param line source code file line number storage (or NULL) [OUT] + * \warning The returned module name and source code file name, if non-NULL, + * are only valid until the logging callback returns. + * + * \version LibVLC 2.1.0 or later + */ +void libvlc_log_get_object(const libvlc_log_t *ctx, const char **name, + const char **header, uintptr_t *id); + /** * Callback prototype for LibVLC log message handler. * \param data data pointer as given to libvlc_log_set() @@ -346,6 +389,8 @@ typedef struct vlc_log_t libvlc_log_t; * \param fmt printf() format string (as defined by ISO C11) * \param args variable argument list for the format * \note Log message handlers must be thread-safe. + * \warning The message context pointer, the format string parameters and the + * variable arguments are only valid until the callback returns. */ typedef void (*libvlc_log_cb)(void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list args); diff --git a/lib/libvlc.sym b/lib/libvlc.sym index 31bf9e9adf..8c431c7ff8 100644 --- a/lib/libvlc.sym +++ b/lib/libvlc.sym @@ -45,6 +45,8 @@ libvlc_get_fullscreen libvlc_get_input_thread libvlc_get_log_verbosity libvlc_get_version +libvlc_log_get_context +libvlc_log_get_object libvlc_log_set libvlc_log_set_file libvlc_log_unset diff --git a/lib/log.c b/lib/log.c index ea883e8dee..fb096e6700 100644 --- a/lib/log.c +++ b/lib/log.c @@ -34,6 +34,33 @@ /*** Logging core dispatcher ***/ +void libvlc_log_get_context(const libvlc_log_t *ctx, + const char **restrict module, + const char **restrict file, + unsigned *restrict line) +{ + if (module != NULL) + *module = ctx->psz_module; + if (file != NULL) + *file = NULL; + if (line != NULL) + *line = 0; +} + +void libvlc_log_get_object(const libvlc_log_t *ctx, + const char **restrict name, + const char **restrict header, + uintptr_t *restrict id) +{ + if (name != NULL) + *name = (ctx->psz_object_type != NULL) + ? ctx->psz_object_type : "generic"; + if (header != NULL) + *header = ctx->psz_header; + if (id != NULL) + *id = ctx->i_object_id; +} + VLC_FORMAT(4,5) static void libvlc_log (libvlc_instance_t *inst, int level, const libvlc_log_t *ctx, const char *fmt, ...)