PipeWire 1.1.0
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1/* PipeWire */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef PIPEWIRE_LOG_H
6#define PIPEWIRE_LOG_H
7
8#include <spa/support/log.h>
9#include <spa/utils/defs.h>
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
29extern enum spa_log_level pw_log_level;
30
31extern struct spa_log_topic * const PW_LOG_TOPIC_DEFAULT;
32
36void pw_log_set(struct spa_log *log);
37
39struct spa_log *pw_log_get(void);
40
43
50int pw_log_set_level_string(const char *str);
51
53void
55 const struct spa_log_topic *topic,
56 const char *file,
57 int line, const char *func,
58 const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
59
61void
63 const struct spa_log_topic *topic,
64 const char *file,
65 int line, const char *func,
66 const char *fmt, va_list args) SPA_PRINTF_FUNC(6, 0);
67
68
69
71void
73 const char *file,
74 int line, const char *func,
75 const char *fmt, ...) SPA_PRINTF_FUNC(5, 6);
76
78void
80 const char *file,
81 int line, const char *func,
82 const char *fmt, va_list args) SPA_PRINTF_FUNC(5, 0);
83
89#define PW_LOG_TOPIC_DEFINE_STATIC(var, topic) \
90 static struct spa_log_topic var = SPA_LOG_TOPIC(SPA_VERSION_LOG_TOPIC, topic); \
91 static void __attribute__((constructor)) var ## _register_construct(void) { pw_log_topic_register(&var); } \
92 static void __attribute__((destructor)) var ## _register_destroy(void) { pw_log_topic_unregister(&var); }
108#define PW_LOG_TOPIC_STATIC(var, topic) \
109 PW_LOG_TOPIC_DEFINE_STATIC(var ## _value, topic) \
110 static struct spa_log_topic * const var = &(var ## _value)
111
116#define PW_LOG_TOPIC_EXTERN(var) \
117 extern struct spa_log_topic * const var
118
123#define PW_LOG_TOPIC(var, topic) \
124 PW_LOG_TOPIC_DEFINE_STATIC(var ## _value, topic) \
125 struct spa_log_topic * const var = &(var ## _value)
126
132#define PW_LOG_TOPIC_INIT(var) \
133 spa_log_topic_init(pw_log_get(), var);
134
144
151
153#define pw_log_level_enabled(lev) (pw_log_level >= (lev))
154#define pw_log_topic_enabled(lev,t) ((t) && (t)->has_custom_level ? (t)->level >= (lev) : pw_log_level_enabled((lev)))
155
156/* check is a custom level was assigned to a topic. \since 1.1.0 */
157#define pw_log_topic_custom_enabled(lev,t) ((t) && (t)->has_custom_level && (t)->level >= (lev))
159#define pw_logtv(lev,topic,fmt,ap) \
160({ \
161 if (SPA_UNLIKELY(pw_log_topic_enabled(lev,topic))) \
162 pw_log_logtv(lev,topic,__FILE__,__LINE__,__func__,fmt,ap); \
163})
165#define pw_logt(lev,topic,...) \
166({ \
167 if (SPA_UNLIKELY(pw_log_topic_enabled(lev,topic))) \
168 pw_log_logt(lev,topic,__FILE__,__LINE__,__func__,__VA_ARGS__); \
169})
171#define pw_log(lev,...) pw_logt(lev,PW_LOG_TOPIC_DEFAULT,__VA_ARGS__)
172
173#define pw_log_error(...) pw_log(SPA_LOG_LEVEL_ERROR,__VA_ARGS__)
174#define pw_log_warn(...) pw_log(SPA_LOG_LEVEL_WARN,__VA_ARGS__)
175#define pw_log_info(...) pw_log(SPA_LOG_LEVEL_INFO,__VA_ARGS__)
176#define pw_log_debug(...) pw_log(SPA_LOG_LEVEL_DEBUG,__VA_ARGS__)
177#define pw_log_trace(...) pw_log(SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
179#define pw_logt_error(t,...) pw_logt(SPA_LOG_LEVEL_ERROR,t,__VA_ARGS__)
180#define pw_logt_warn(t,...) pw_logt(SPA_LOG_LEVEL_WARN,t,__VA_ARGS__)
181#define pw_logt_info(t,...) pw_logt(SPA_LOG_LEVEL_INFO,t,__VA_ARGS__)
182#define pw_logt_debug(t,...) pw_logt(SPA_LOG_LEVEL_DEBUG,t,__VA_ARGS__)
183#define pw_logt_trace(t,...) pw_logt(SPA_LOG_LEVEL_TRACE,t,__VA_ARGS__)
185#ifndef FASTPATH
186#define pw_log_trace_fp(...) pw_log(SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
187#else
188#define pw_log_trace_fp(...)
189#endif
190
195#ifdef __cplusplus
196}
197#endif
198#endif /* PIPEWIRE_LOG_H */
spa/utils/defs.h
struct spa_log * pw_log_get(void)
Get the log interface.
Definition log.c:217
void pw_log_logtv(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)
Log a message for a topic.
Definition log.c:383
struct spa_log_topic *const PW_LOG_TOPIC_DEFAULT
Definition log.c:31
void pw_log_topic_unregister(struct spa_log_topic *t)
Unregister log topic.
Definition log.c:157
void pw_log_logt(enum spa_log_level level, const struct spa_log_topic *topic, const char *file, int line, const char *func, const char *fmt,...)
Log a message for a topic.
Definition log.c:356
void pw_log_set(struct spa_log *log)
Configure a logging module.
Definition log.c:202
void pw_log_topic_register(struct spa_log_topic *t)
Register log topic with the logger, to enable dynamic log levels.
Definition log.c:136
int pw_log_set_level_string(const char *str)
Configure the logging level using a string in PIPEWIRE_DEBUG format.
Definition log.c:319
void pw_log_log(enum spa_log_level level, const char *file, int line, const char *func, const char *fmt,...)
Log a message for the default topic.
Definition log.c:427
void pw_log_set_level(enum spa_log_level level)
Configure the logging level.
Definition log.c:226
void pw_log_logv(enum spa_log_level level, const char *file, int line, const char *func, const char *fmt, va_list args)
Log a message for the default topic.
Definition log.c:406
enum spa_log_level pw_log_level
The global log level.
Definition log.c:26
spa_log_level
Definition log.h:45
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:285
spa/support/log.h
Identifier for a topic.
Definition log.h:83
Definition log.h:61
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition log.h:70