]> git.sesse.net Git - vlc/commitdiff
logger: track file, line and function for debug
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 8 Feb 2015 12:23:34 +0000 (14:23 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 8 Feb 2015 12:57:17 +0000 (14:57 +0200)
include/vlc_messages.h
src/misc/messages.c

index 045e9e8d51121a3e28156d47c77c159cf106d469..2da692e65ccd927807a34663a5e96fe952ffb997 100644 (file)
@@ -60,23 +60,32 @@ typedef struct vlc_log_t
     const char *psz_object_type; /**< Emitter object type name */
     const char *psz_module; /**< Emitter module (source code) */
     const char *psz_header; /**< Additional header (used by VLM media) */
+    const char *file; /**< Source code file name or NULL */
+    int line; /**< Source code file line number or -1 */
+    const char *func; /**< Source code calling function name or NULL */
 } vlc_log_t;
 
-VLC_API void vlc_Log(vlc_object_t *, int,
-                     const char *, const char *, ...) VLC_FORMAT( 4, 5 );
-VLC_API void vlc_vaLog(vlc_object_t *, int,
-                       const char *, const char *, va_list);
-#define msg_GenericVa(a, b, c, d) \
-    vlc_vaLog(VLC_OBJECT(a), b, MODULE_STRING, c, d)
+VLC_API void vlc_Log(vlc_object_t *obj, int prio, const char *module,
+                     const char *file, unsigned line, const char *func,
+                     const char *format, ...) VLC_FORMAT(7, 8);
+VLC_API void vlc_vaLog(vlc_object_t *obj, int prio, const char *module,
+                       const char *file, unsigned line, const char *func,
+                       const char *format, va_list ap);
+#define msg_GenericVa(o, p, fmt, ap) \
+    vlc_vaLog(VLC_OBJECT(o), p, MODULE_STRING, __FILE__, __LINE__, __func__, \
+              fmt, ap)
 
-#define msg_Info( p_this, ... ) \
-    vlc_Log( VLC_OBJECT(p_this), VLC_MSG_INFO, MODULE_STRING, __VA_ARGS__ )
-#define msg_Err( p_this, ... ) \
-    vlc_Log( VLC_OBJECT(p_this), VLC_MSG_ERR,  MODULE_STRING, __VA_ARGS__ )
-#define msg_Warn( p_this, ... ) \
-    vlc_Log( VLC_OBJECT(p_this), VLC_MSG_WARN, MODULE_STRING, __VA_ARGS__ )
-#define msg_Dbg( p_this, ... ) \
-    vlc_Log( VLC_OBJECT(p_this), VLC_MSG_DBG,  MODULE_STRING, __VA_ARGS__ )
+#define msg_Generic(o, p, ...) \
+    vlc_Log(VLC_OBJECT(o), p, MODULE_STRING, __FILE__, __LINE__, \
+            __func__, __VA_ARGS__)
+#define msg_Info(p_this, ...) \
+    msg_Generic(p_this, VLC_MSG_INFO, __VA_ARGS__)
+#define msg_Err(p_this, ...) \
+    msg_Generic(p_this, VLC_MSG_ERR, __VA_ARGS__)
+#define msg_Warn(p_this, ...) \
+    msg_Generic(p_this, VLC_MSG_WARN, __VA_ARGS__)
+#define msg_Dbg(p_this, ...) \
+    msg_Generic(p_this, VLC_MSG_DBG, __VA_ARGS__)
 
 #ifndef MODULE_STRING
 # define MODULE_STRING __FILE__
index 77a5ec9f4f4961819c52d86e29bf753fa4681cb2..3679ade29531680ddcc7b1fb2879a1968057307b 100644 (file)
@@ -88,6 +88,7 @@ static void Win32DebugOutputMsg (void *, int , const vlc_log_t *,
  * to vlc_Log().
  */
 void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
+                const char *file, unsigned line, const char *func,
                 const char *format, va_list args)
 {
     if (obj != NULL && obj->i_flags & OBJECT_FLAGS_QUIET)
@@ -115,6 +116,9 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
     msg.psz_object_type = (obj != NULL) ? obj->psz_object_type : "generic";
     msg.psz_module = module;
     msg.psz_header = NULL;
+    msg.file = file;
+    msg.line = line;
+    msg.func = func;
 
     for (vlc_object_t *o = obj; o != NULL; o = o->p_parent)
         if (o->psz_header != NULL)
@@ -142,15 +146,19 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
  * \param type VLC_MSG_* message type (info, error, warning or debug)
  * \param module name of module from which the message come
  *               (normally MODULE_STRING)
+ * \param file source module file name (normally __FILE__) or NULL
+ * \param line function call source line number (normally __LINE__) or 0
+ * \param func calling function name (normally __func__) or NULL
  * \param format printf-like message format
  */
 void vlc_Log(vlc_object_t *obj, int type, const char *module,
+             const char *file, unsigned line, const char *func,
              const char *format, ... )
 {
     va_list ap;
 
     va_start(ap, format);
-    vlc_vaLog(obj, type, module, format, ap);
+    vlc_vaLog(obj, type, module, file, line, func, format, ap);
     va_end(ap);
 }
 
@@ -265,6 +273,9 @@ static void vlc_vaLogEarly(void *d, int type, const vlc_log_t *item,
     log->meta.psz_object_type = item->psz_object_type;
     log->meta.psz_module = item->psz_module; /* Ditto. */
     log->meta.psz_header = item->psz_header ? strdup(item->psz_header) : NULL;
+    log->meta.file = item->file;
+    log->meta.line = item->line;
+    log->meta.func = item->func;
 
     int canc = vlc_savecancel(); /* XXX: needed for vasprintf() ? */
     if (vasprintf(&log->msg, format, ap) == -1)