mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
spa: implement the new topic logging for the provided loggers
Both simple log implementation now support the new topic-based functions, and so does the journal logger too.
This commit is contained in:
parent
0e60e9c063
commit
59a5791d41
7 changed files with 366 additions and 27 deletions
|
|
@ -39,8 +39,9 @@ extern "C" {
|
|||
* \{
|
||||
*/
|
||||
|
||||
static inline SPA_PRINTF_FUNC(6, 0) void spa_log_impl_logv(void *object,
|
||||
static inline SPA_PRINTF_FUNC(7, 0) void spa_log_impl_logtv(void *object,
|
||||
enum spa_log_level level,
|
||||
const struct spa_log_topic *topic,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
|
|
@ -50,18 +51,50 @@ static inline SPA_PRINTF_FUNC(6, 0) void spa_log_impl_logv(void *object,
|
|||
static const char * const levels[] = { "-", "E", "W", "I", "D", "T" };
|
||||
|
||||
const char *basename = strrchr(file, '/');
|
||||
char text[512], location[1024];
|
||||
char text[512], location[1024];
|
||||
char topicstr[32] = {0};
|
||||
|
||||
if (basename)
|
||||
basename += 1; /* skip '/' */
|
||||
else
|
||||
basename = file; /* use whole string if no '/' is found */
|
||||
|
||||
vsnprintf(text, sizeof(text), fmt, args);
|
||||
snprintf(location, sizeof(location), "[%s][%s:%i %s()] %s\n",
|
||||
levels[level], basename, line, func, text);
|
||||
fputs(location, stderr);
|
||||
if (topic && topic->topic)
|
||||
snprintf(topicstr, sizeof(topicstr), " %s ", topic->topic);
|
||||
vsnprintf(text, sizeof(text), fmt, args);
|
||||
snprintf(location, sizeof(location), "[%s]%s[%s:%i %s()] %s\n",
|
||||
levels[level],
|
||||
topicstr,
|
||||
basename, line, func, text);
|
||||
fputs(location, stderr);
|
||||
}
|
||||
|
||||
static inline SPA_PRINTF_FUNC(7,8) void spa_log_impl_logt(void *object,
|
||||
enum spa_log_level level,
|
||||
const struct spa_log_topic *topic,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
spa_log_impl_logtv(object, level, topic, file, line, func, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static inline SPA_PRINTF_FUNC(6, 0) void spa_log_impl_logv(void *object,
|
||||
enum spa_log_level level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt,
|
||||
va_list args)
|
||||
{
|
||||
|
||||
spa_log_impl_logtv(object, level, NULL, file, line, func, fmt, args);
|
||||
}
|
||||
|
||||
static inline SPA_PRINTF_FUNC(6,7) void spa_log_impl_log(void *object,
|
||||
enum spa_log_level level,
|
||||
const char *file,
|
||||
|
|
@ -75,6 +108,11 @@ static inline SPA_PRINTF_FUNC(6,7) void spa_log_impl_log(void *object,
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
static inline void spa_log_impl_topic_init(void *object, struct spa_log_topic *topic)
|
||||
{
|
||||
/* noop */
|
||||
}
|
||||
|
||||
#define SPA_LOG_IMPL_DEFINE(name) \
|
||||
struct { \
|
||||
struct spa_log log; \
|
||||
|
|
@ -85,9 +123,12 @@ struct { \
|
|||
{ { { SPA_TYPE_INTERFACE_Log, SPA_VERSION_LOG, \
|
||||
SPA_CALLBACKS_INIT(&name.methods, &name) }, \
|
||||
SPA_LOG_LEVEL_INFO, }, \
|
||||
{ SPA_VERSION_LOG_METHODS, \
|
||||
{ SPA_VERSION_LOG_METHODS_LOGT, \
|
||||
spa_log_impl_log, \
|
||||
spa_log_impl_logv,} }
|
||||
spa_log_impl_logv, \
|
||||
spa_log_impl_logt, \
|
||||
spa_log_impl_logtv, \
|
||||
} }
|
||||
|
||||
#define SPA_LOG_IMPL(name) \
|
||||
SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT(name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue