PipeWire 1.6.8

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
12 extern "C" {
13#endif
14
23
29 extern enum spa_log_level pw_log_level;
30
31 extern struct spa_log_topic * const PW_LOG_TOPIC_DEFAULT;
32
36 void pw_log_set(struct spa_log *log);
37
39 struct spa_log *pw_log_get(void);
40
42 void pw_log_set_level(enum spa_log_level level);
43
50 int pw_log_set_level_string(const char *str);
51
53 void
54 pw_log_logt(enum spa_log_level level,
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
61 void
62 pw_log_logtv(enum spa_log_level level,
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
71 void
72 pw_log_log(enum spa_log_level level,
73 const char *file,
74 int line, const char *func,
75 const char *fmt, ...) SPA_PRINTF_FUNC(5, 6);
76
78 void
79 pw_log_logv(enum spa_log_level level,
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); }
93
97
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
113 * Declare a static log topic named \a var.
114 * See \ref PW_LOG_TOPIC_STATIC for an example usage.
115 */
116#define PW_LOG_TOPIC_EXTERN(var) \
117 extern struct spa_log_topic * const var
118
121 * See \ref PW_LOG_TOPIC_STATIC for an example usage.
122 */
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
128 * \deprecated Use \ref pw_log_topic_register and \ref pw_log_topic_unregister
129 * instead, or rely on the auto-registration by \ref PW_LOG_TOPIC and
130 * \ref PW_LOG_TOPIC_STATIC.
131 */
132#define PW_LOG_TOPIC_INIT(var) \
133 spa_log_topic_init(pw_log_get(), var);
134
137 * Topic must be unregistered before freeing it or plugin unload.
138 * May be used instead of \ref PW_LOG_TOPIC_INIT
139 * This function is threadsafe.
140 *
141 * \since 1.1.0
142 */
143 void pw_log_topic_register(struct spa_log_topic *t);
144
150 void pw_log_topic_unregister(struct spa_log_topic *t);
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))
158
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})
164
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})
170
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__)
178
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__)
184
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
194
195#ifdef __cplusplus
196}
197#endif
198#endif /* PIPEWIRE_LOG_H */
defs.h
spa/utils/defs.h
args
uint32_t int int const char va_list args
Definition core.h:434
pw_log_get
struct spa_log * pw_log_get(void)
Get the log interface.
Definition log.c:217
pw_log_logtv
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
PW_LOG_TOPIC_DEFAULT
struct spa_log_topic *const PW_LOG_TOPIC_DEFAULT
Definition log.c:30
pw_log_topic_unregister
void pw_log_topic_unregister(struct spa_log_topic *t)
Unregister log topic.
Definition log.c:157
pw_log_logt
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
pw_log_set
void pw_log_set(struct spa_log *log)
Configure a logging module.
Definition log.c:202
pw_log_topic_register
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
pw_log_set_level_string
int pw_log_set_level_string(const char *str)
Configure the logging level using a string in PIPEWIRE_DEBUG format.
Definition log.c:319
pw_log_log
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
pw_log_set_level
void pw_log_set_level(enum spa_log_level level)
Configure the logging level.
Definition log.c:226
pw_log_logv
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
pw_log_level
enum spa_log_level pw_log_level
The global log level.
Definition log.c:25
spa_log_level
spa_log_level
Definition log.h:55
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:297
log.h
spa/support/log.h
spa_log_topic
Identifier for a topic.
Definition log.h:93
spa_log
Definition log.h:71
spa_log::level
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition log.h:80