spa: add debug log context

Make a real debug context with a log function and move it to a new file.
This way we don't need to redefine a macro.
Make a new context for debugging to a log file. Make new functions to
debug to a log file.
Move the stringbuffer to string utils.
Integrate file/line/func and topics into the debug log.
We can remove some more things from the pipewire log_object function and
also add support for topics.
This commit is contained in:
Wim Taymans 2023-01-18 17:41:16 +01:00
parent 3c67821c4a
commit 6207d98ff1
21 changed files with 231 additions and 164 deletions

View file

@ -34,7 +34,6 @@
#include <pipewire/log.h>
#include "log.h"
#define spa_debug pw_log_debug
#include <spa/support/cpu.h>
#include <spa/utils/result.h>

View file

@ -232,35 +232,21 @@ pw_log_log(enum spa_log_level level,
* realtime threads
*/
struct log_ctx {
enum spa_log_level level;
const char *file;
int line;
const char *func;
};
#undef spa_debugc
#define spa_debugc(_ctx,_fmt,...) \
({ struct log_ctx *_c = _ctx; \
pw_log_log(_c->level, _c->file, _c->line, _c->func, \
_fmt, ## __VA_ARGS__); \
})
#include <spa/debug/pod.h>
#include <spa/debug/log.h>
void pw_log_log_object(enum spa_log_level level,
const char *file,
int line,
const char *func,
uint32_t flags, const void *object)
const struct spa_log_topic *topic, const char *file,
int line, const char *func, uint32_t flags, const void *object)
{
struct log_ctx ctx = { level, file, line, func, };
struct spa_debug_log_ctx ctx = SPA_LOGF_DEBUG_INIT(global_log, level,
topic, file, line, func );
if (flags & PW_LOG_OBJECT_POD) {
const struct spa_pod *pod = object;
if (pod == NULL) {
pw_log_log(level, file, line, func, "NULL");
pw_log_logt(level, topic, file, line, func, "NULL");
} else {
spa_debugc_pod(&ctx, 0, SPA_TYPE_ROOT, pod);
spa_debugc_pod(&ctx.ctx, 0, SPA_TYPE_ROOT, pod);
}
}
}

View file

@ -45,10 +45,6 @@ struct ucred {
};
#endif
#ifndef spa_debug
#define spa_debug(...) pw_log_trace(__VA_ARGS__)
#endif
#define MAX_RATES 32u
#define CLOCK_MIN_QUANTUM 4u
#define CLOCK_MAX_QUANTUM 65536u
@ -1282,17 +1278,19 @@ void pw_control_destroy(struct pw_control *control);
void pw_impl_client_unref(struct pw_impl_client *client);
#define PW_LOG_OBJECT_POD (1<<0)
void pw_log_log_object(enum spa_log_level level, const char *file, int line,
const char *func, uint32_t flags, const void *object);
void pw_log_log_object(enum spa_log_level level, const struct spa_log_topic *topic,
const char *file, int line, const char *func, uint32_t flags,
const void *object);
#define pw_log_object(lev,fl,obj) \
({ \
if (SPA_UNLIKELY(pw_log_level_enabled (lev))) \
pw_log_log_object(lev,__FILE__,__LINE__,__func__,(fl),(obj)); \
#define pw_log_object(lev,t,fl,obj) \
({ \
if (SPA_UNLIKELY(pw_log_topic_enabled(lev,t))) \
pw_log_log_object(lev,t,__FILE__,__LINE__, \
__func__,(fl),(obj)); \
})
#define pw_log_pod(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod)
#define pw_log_format(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod)
#define pw_log_pod(lev,pod) pw_log_object(lev,PW_LOG_TOPIC_DEFAULT,PW_LOG_OBJECT_POD,pod)
#define pw_log_format(lev,pod) pw_log_object(lev,PW_LOG_TOPIC_DEFAULT,PW_LOG_OBJECT_POD,pod)
bool pw_log_is_default(void);