[vlc-commits] libvlc: add functions to query log message "item" data

Rémi Denis-Courmont git at videolan.org
Wed Mar 20 18:21:28 CET 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Mar 20 19:18:59 2013 +0200| [dac9ab984c7a2017780cae79b8642892514b63c9] | committer: Rémi Denis-Courmont

libvlc: add functions to query log message "item" data

Also make provisions for file name and line number in the future.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=dac9ab984c7a2017780cae79b8642892514b63c9
---

 include/vlc/libvlc.h |   45 +++++++++++++++++++++++++++++++++++++++++++++
 lib/libvlc.sym       |    2 ++
 lib/log.c            |   27 +++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)

diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h
index 71f9a6b..ab1030d 100644
--- a/include/vlc/libvlc.h
+++ b/include/vlc/libvlc.h
@@ -339,6 +339,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 <b>manual</b>
+ * 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()
  * \param level message level (@ref enum libvlc_log_level)
@@ -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 <b>must</b> 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 31bf9e9..8c431c7 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 ea883e8..fb096e6 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, ...)



More information about the vlc-commits mailing list