log: add wp_logt_checked taking WpLogTopic, to decide on debug messages
Make decision on whether to show code location in journal messages based on whether the WpLogTopic would enable DEBUG level messages. Add wp_logt_checked API to take WpLogTopic as input to make this possible, and deprecate wp_log_checked.
This commit is contained in:

committed by
George Kiagiadakis

parent
8016ad1cec
commit
2fb055f43d
41
lib/wp/log.c
41
lib/wp/log.c
@@ -892,6 +892,8 @@ wp_log_writer_default (GLogLevelFlags log_level_flags,
|
||||
/*!
|
||||
* \brief Used internally by the debug logging macros. Avoid using it directly.
|
||||
*
|
||||
* \deprecated Use \ref wp_logt_checked instead.
|
||||
*
|
||||
* This assumes that the arguments are correct and that the log_topic is
|
||||
* enabled for the given log_level. No additional checks are performed.
|
||||
* \ingroup wplog
|
||||
@@ -922,6 +924,45 @@ wp_log_checked (
|
||||
wp_log_fields_log (&lf);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Used internally by the debug logging macros. Avoid using it directly.
|
||||
*
|
||||
* This assumes that the arguments are correct and that the log_topic is
|
||||
* enabled for the given log_level. No additional checks are performed.
|
||||
* \ingroup wplog
|
||||
*/
|
||||
void
|
||||
wp_logt_checked (
|
||||
const WpLogTopic *topic,
|
||||
GLogLevelFlags log_level_flags,
|
||||
const gchar *file,
|
||||
const gchar *line,
|
||||
const gchar *func,
|
||||
GType object_type,
|
||||
gconstpointer object,
|
||||
const gchar *message_format,
|
||||
...)
|
||||
{
|
||||
WpLogFields lf = {0};
|
||||
g_autofree gchar *message = NULL;
|
||||
va_list args;
|
||||
const gchar *log_topic = topic ? topic->topic_name : NULL;
|
||||
gboolean debug;
|
||||
|
||||
if (topic)
|
||||
debug = (topic->flags & WP_LOG_TOPIC_LEVEL_MASK & G_LOG_LEVEL_DEBUG);
|
||||
else
|
||||
debug = wp_want_debug_log (NULL);
|
||||
|
||||
va_start (args, message_format);
|
||||
message = g_strdup_vprintf (message_format, args);
|
||||
va_end (args);
|
||||
|
||||
wp_log_fields_init (&lf, log_topic, level_index_from_flags (log_level_flags), debug,
|
||||
file, line, func, object_type, object, message);
|
||||
wp_log_fields_log (&lf);
|
||||
}
|
||||
|
||||
static G_GNUC_PRINTF (7, 0) void
|
||||
wp_spa_log_logtv (void *object,
|
||||
enum spa_log_level level,
|
||||
|
@@ -121,6 +121,12 @@ GLogWriterOutput wp_log_writer_default (GLogLevelFlags log_level,
|
||||
|
||||
WP_API
|
||||
void wp_log_checked (const gchar *log_topic, GLogLevelFlags log_level,
|
||||
const gchar *file, const gchar *line, const gchar *func,
|
||||
GType object_type, gconstpointer object,
|
||||
const gchar *message_format, ...) G_GNUC_PRINTF (8, 9) __attribute__ ((deprecated));
|
||||
|
||||
WP_API
|
||||
void wp_logt_checked (const WpLogTopic *topic, GLogLevelFlags log_level,
|
||||
const gchar *file, const gchar *line, const gchar *func,
|
||||
GType object_type, gconstpointer object,
|
||||
const gchar *message_format, ...) G_GNUC_PRINTF (8, 9);
|
||||
@@ -128,7 +134,7 @@ void wp_log_checked (const gchar *log_topic, GLogLevelFlags log_level,
|
||||
#define wp_log(topic, level, type, object, ...) \
|
||||
({ \
|
||||
if (G_UNLIKELY (wp_log_topic_is_enabled (topic, level))) \
|
||||
wp_log_checked (topic->topic_name, level, __FILE__, G_STRINGIFY (__LINE__), \
|
||||
wp_logt_checked (topic, level, __FILE__, G_STRINGIFY (__LINE__), \
|
||||
G_STRFUNC, type, object, __VA_ARGS__); \
|
||||
})
|
||||
|
||||
|
@@ -384,7 +384,7 @@ log_log (lua_State *L, GLogLevelFlags lvl)
|
||||
snprintf (line_str, 11, "%d", ar.currentline);
|
||||
ar.name = ar.name ? ar.name : "chunk";
|
||||
|
||||
wp_log_checked (topic->topic_name, lvl,
|
||||
wp_logt_checked (topic, lvl,
|
||||
ar.source, line_str, ar.name, type, instance, "%s", message);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user