[vlc-commits] messages: separate logging w/ and w/o object
Rémi Denis-Courmont
git at videolan.org
Mon Mar 4 21:05:52 CET 2019
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Mar 4 20:23:40 2019 +0200| [b3739d3934100311fe7dfff44fb3645475c54dea] | committer: Rémi Denis-Courmont
messages: separate logging w/ and w/o object
As discussed at the last workshop; the main caveat is that the object
type string must still be had from something.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b3739d3934100311fe7dfff44fb3645475c54dea
---
include/vlc_messages.h | 48 ++++++++++++++++++++++++++++++++++---------
modules/access/http/connmgr.c | 6 ++++--
src/libvlccore.sym | 2 ++
src/misc/messages.c | 36 +++++++++++---------------------
src/misc/objects.c | 27 ++++++++++++++++++++++++
5 files changed, 83 insertions(+), 36 deletions(-)
diff --git a/include/vlc_messages.h b/include/vlc_messages.h
index 2cf1b7d2a1..ba0646780f 100644
--- a/include/vlc_messages.h
+++ b/include/vlc_messages.h
@@ -64,19 +64,38 @@ typedef struct vlc_log_t
unsigned long tid; /**< Emitter thread ID */
} vlc_log_t;
-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);
+/**
+ * Emit a log message.
+ *
+ * \param obj VLC object emitting the message or NULL
+ * \param type VLC_MSG_* message type (info, error, warning or debug)
+ * \param module name of module from which the message come
+ * (normally vlc_module_name)
+ * \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
+ */
+VLC_API void vlc_object_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);
+
+/**
+ * Emit a log message.
+ *
+ * This function is the variable argument list equivalent to vlc_object_Log().
+ */
+VLC_API void vlc_object_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, vlc_module_name, __FILE__, __LINE__, \
- __func__, fmt, ap)
+ vlc_object_vaLog(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
+ __func__, fmt, ap)
#define msg_Generic(o, p, ...) \
- vlc_Log(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
- __func__, __VA_ARGS__)
+ vlc_object_Log(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
+ __func__, __VA_ARGS__)
#define msg_Info(p_this, ...) \
msg_Generic(p_this, VLC_MSG_INFO, __VA_ARGS__)
#define msg_Err(p_this, ...) \
@@ -100,6 +119,15 @@ VLC_API const char *vlc_strerror_c(int);
struct vlc_logger;
+VLC_API void vlc_Log(struct vlc_logger *const *logger, int prio,
+ const char *type, const char *module,
+ const char *file, unsigned line, const char *func,
+ const char *format, ...) VLC_FORMAT(8, 9);
+VLC_API void vlc_vaLog(struct vlc_logger *const *logger, int prio,
+ const char *type, const char *module,
+ const char *file, unsigned line, const char *func,
+ const char *format, va_list ap);
+
/**
* Message logging callback signature.
* \param data data pointer as provided to vlc_msg_SetCallback().
diff --git a/modules/access/http/connmgr.c b/modules/access/http/connmgr.c
index 5f527106a7..e84c862153 100644
--- a/modules/access/http/connmgr.c
+++ b/modules/access/http/connmgr.c
@@ -39,7 +39,8 @@ void vlc_http_err(void *ctx, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
- vlc_vaLog(ctx, VLC_MSG_ERR, "http", __FILE__, __LINE__, __func__, fmt, ap);
+ vlc_object_vaLog(ctx, VLC_MSG_ERR, "http", __FILE__, __LINE__, __func__,
+ fmt, ap);
va_end(ap);
}
@@ -48,7 +49,8 @@ void vlc_http_dbg(void *ctx, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
- vlc_vaLog(ctx, VLC_MSG_DBG, "http", __FILE__, __LINE__, __func__, fmt, ap);
+ vlc_object_vaLog(ctx, VLC_MSG_DBG, "http", __FILE__, __LINE__, __func__,
+ fmt, ap);
va_end(ap);
}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 202a6a1d21..d64cadd249 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -676,6 +676,8 @@ vlc_object_hold
vlc_object_release
vlc_object_typename
vlc_object_parent
+vlc_object_Log
+vlc_object_vaLog
vlc_once
vlc_rand_bytes
vlc_drand48
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 3de4002be2..2a6e904682 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -82,14 +82,12 @@ static void Win32DebugOutputMsg (void *, int , const vlc_log_t *,
const char *, va_list);
#endif
-/**
- * Emit a log message. This function is the variable argument list equivalent
- * 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)
+void vlc_vaLog(struct vlc_logger *const *loggerp, int type,
+ const char *typename, const char *module,
+ const char *file, unsigned line, const char *func,
+ const char *format, va_list args)
{
+ struct vlc_logger *logger = *loggerp;
/* Get basename from the module filename */
char *p = strrchr(module, '/');
if (p != NULL)
@@ -108,8 +106,8 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
/* Fill message information fields */
vlc_log_t msg;
- msg.i_object_id = (uintptr_t)obj;
- msg.psz_object_type = (obj != NULL) ? vlc_object_typename(obj) : "generic";
+ msg.i_object_id = (uintptr_t)(void *)loggerp;
+ msg.psz_object_type = typename;
msg.psz_module = module;
msg.psz_header = NULL;
msg.file = file;
@@ -126,29 +124,19 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
#endif
/* Pass message to the callback */
- if (obj != NULL)
- vlc_vaLogCallback(obj->obj.logger, type, &msg, format, args);
+ if (logger != NULL)
+ vlc_vaLogCallback(logger, type, &msg, format, args);
}
-/**
- * Emit a log message.
- * \param obj VLC object emitting the message or NULL
- * \param type VLC_MSG_* message type (info, error, warning or debug)
- * \param module name of module from which the message come
- * (normally vlc_module_name)
- * \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,
+void vlc_Log(struct vlc_logger *const *logger, int type,
+ const char *typename, 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, file, line, func, format, ap);
+ vlc_vaLog(logger, type, typename, module, file, line, func, format, ap);
va_end(ap);
}
diff --git a/src/misc/objects.c b/src/misc/objects.c
index 855211d47e..ad93799223 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -429,6 +429,33 @@ void vlc_object_release (vlc_object_t *obj)
}
}
+void vlc_object_vaLog(vlc_object_t *obj, int prio, const char *module,
+ const char *file, unsigned line, const char *func,
+ const char *format, va_list ap)
+{
+ if (obj == NULL)
+ return;
+
+ const char *typename = vlc_object_typename(obj);
+ /* FIXME: libvlc allows NULL type but modules don't */
+ if (typename == NULL)
+ typename = "generic";
+
+ vlc_vaLog(&obj->obj.logger, prio, typename, module, file, line, func,
+ format, ap);
+}
+
+void vlc_object_Log(vlc_object_t *obj, int prio, const char *module,
+ const char *file, unsigned line, const char *func,
+ const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ vlc_object_vaLog(obj, prio, module, file, line, func, format, ap);
+ va_end(ap);
+}
+
/**
* Lists the children of an object.
*
More information about the vlc-commits
mailing list