no bug - Correct some typos in the comments. a=typo-fix
[gecko.git] / third_party / pipewire / pipewire / log.h
blob26ffc20f9a0d6e5d3690abb6192079bf40c565f3
1 /* PipeWire
3 * Copyright © 2018 Wim Taymans
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 #ifndef PIPEWIRE_LOG_H
26 #define PIPEWIRE_LOG_H
28 #include <spa/support/log.h>
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
34 /** \defgroup pw_log Logging
36 * \brief Logging functions of PipeWire
38 * Logging is performed to stdout and stderr. Trace logging is performed
39 * in a lockfree ringbuffer and written out from the main thread as to not
40 * block the realtime threads.
43 /**
44 * \addtogroup pw_log
45 * \{
47 /** The global log level */
48 extern enum spa_log_level pw_log_level;
50 extern struct spa_log_topic *PW_LOG_TOPIC_DEFAULT;
52 /** Configure a logging module. This is usually done automatically
53 * in pw_init() but you can install a custom logger before calling
54 * pw_init(). */
55 void pw_log_set(struct spa_log *log);
57 /** Get the log interface */
58 struct spa_log *pw_log_get(void);
60 /** Configure the logging level */
61 void pw_log_set_level(enum spa_log_level level);
63 /** Log a message for a topic */
64 void
65 pw_log_logt(enum spa_log_level level,
66 const struct spa_log_topic *topic,
67 const char *file,
68 int line, const char *func,
69 const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
71 /** Log a message for a topic */
72 void
73 pw_log_logtv(enum spa_log_level level,
74 const struct spa_log_topic *topic,
75 const char *file,
76 int line, const char *func,
77 const char *fmt, va_list args) SPA_PRINTF_FUNC(6, 0);
81 /** Log a message for the default topic */
82 void
83 pw_log_log(enum spa_log_level level,
84 const char *file,
85 int line, const char *func,
86 const char *fmt, ...) SPA_PRINTF_FUNC(5, 6);
88 /** Log a message for the default topic */
89 void
90 pw_log_logv(enum spa_log_level level,
91 const char *file,
92 int line, const char *func,
93 const char *fmt, va_list args) SPA_PRINTF_FUNC(5, 0);
95 /** Initialize the log topic. The returned topic is owned by the pipewire
96 * context and the topic must not be modified or freed.
97 * Do not use this function directly, use one of PW_LOG_TOPIC_* instead.
99 * \see PW_LOG_TOPIC_STATIC
100 * \see PW_LOG_TOPIC_EXTERN
101 * \see PW_LOG_TOPIC
103 void
104 _pw_log_topic_new(struct spa_log_topic *topic);
107 * Declare a static log topic named \a var. The usual usage is:
108 * \code
109 * PW_LOG_TOPIC_STATIC(my_topic);
110 * #define PW_LOG_TOPIC_DEFAULT my_topic
112 * void foo() {
113 * pw_log_debug("bar");
115 * \endcode
117 #define PW_LOG_TOPIC_STATIC(var, topic) \
118 static struct spa_log_topic var##__LINE__ = SPA_LOG_TOPIC(0, topic); \
119 static struct spa_log_topic *var = &(var##__LINE__)
122 * Declare a static log topic named \a var.
123 * See \ref PW_LOG_TOPIC_STATIC for an example usage.
125 #define PW_LOG_TOPIC_EXTERN(var) \
126 extern struct spa_log_topic *var
129 * Declare a static log topic named \a var.
130 * See \ref PW_LOG_TOPIC_STATIC for an example usage.
132 #define PW_LOG_TOPIC(var, topic) \
133 struct spa_log_topic var##__LINE__ = SPA_LOG_TOPIC(0, topic); \
134 struct spa_log_topic *var = &(var##__LINE__)
136 #define PW_LOG_TOPIC_INIT(var) \
137 spa_log_topic_init(pw_log_get(), var);
139 /** Check if a loglevel is enabled */
140 #define pw_log_level_enabled(lev) (pw_log_level >= (lev))
141 #define pw_log_topic_enabled(lev,t) ((t) && (t)->has_custom_level ? (t)->level >= (lev) : pw_log_level_enabled((lev)))
143 #define pw_logtv(lev,topic,fmt,ap) \
144 ({ \
145 if (SPA_UNLIKELY(pw_log_topic_enabled(lev,topic))) \
146 pw_log_logtv(lev,topic,__FILE__,__LINE__,__func__,fmt,ap); \
149 #define pw_logt(lev,topic,...) \
150 ({ \
151 if (SPA_UNLIKELY(pw_log_topic_enabled(lev,topic))) \
152 pw_log_logt(lev,topic,__FILE__,__LINE__,__func__,__VA_ARGS__); \
155 #define pw_log(lev,...) pw_logt(lev,PW_LOG_TOPIC_DEFAULT,__VA_ARGS__)
157 #define pw_log_error(...) pw_log(SPA_LOG_LEVEL_ERROR,__VA_ARGS__)
158 #define pw_log_warn(...) pw_log(SPA_LOG_LEVEL_WARN,__VA_ARGS__)
159 #define pw_log_info(...) pw_log(SPA_LOG_LEVEL_INFO,__VA_ARGS__)
160 #define pw_log_debug(...) pw_log(SPA_LOG_LEVEL_DEBUG,__VA_ARGS__)
161 #define pw_log_trace(...) pw_log(SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
163 #define pw_logt_error(t,...) pw_logt(SPA_LOG_LEVEL_ERROR,t,__VA_ARGS__)
164 #define pw_logt_warn(t,...) pw_logt(SPA_LOG_LEVEL_WARN,t,__VA_ARGS__)
165 #define pw_logt_info(t,...) pw_logt(SPA_LOG_LEVEL_INFO,t,__VA_ARGS__)
166 #define pw_logt_debug(t,...) pw_logt(SPA_LOG_LEVEL_DEBUG,t,__VA_ARGS__)
167 #define pw_logt_trace(t,...) pw_logt(SPA_LOG_LEVEL_TRACE,t,__VA_ARGS__)
169 #ifndef FASTPATH
170 #define pw_log_trace_fp(...) pw_log(SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
171 #else
172 #define pw_log_trace_fp(...)
173 #endif
176 * \}
179 #ifdef __cplusplus
181 #endif
182 #endif /* PIPEWIRE_LOG_H */