PipeWire  0.3.40
log.h
Go to the documentation of this file.
1 /* PipeWire
2  *
3  * Copyright © 2018 Wim Taymans
4  *
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:
11  *
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.
15  *
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.
23  */
24 
25 #ifndef PIPEWIRE_LOG_H
26 #define PIPEWIRE_LOG_H
27 
28 #include <spa/support/log.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
48 extern enum spa_log_level pw_log_level;
49 
50 extern struct spa_log_topic *PW_LOG_TOPIC_DEFAULT;
51 
55 void pw_log_set(struct spa_log *log);
56 
58 struct spa_log *pw_log_get(void);
59 
62 
64 void
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);
70 
72 void
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);
78 
79 
80 
82 void
84  const char *file,
85  int line, const char *func,
86  const char *fmt, ...) SPA_PRINTF_FUNC(5, 6);
87 
89 void
91  const char *file,
92  int line, const char *func,
93  const char *fmt, va_list args) SPA_PRINTF_FUNC(5, 0);
94 
103 void
104 _pw_log_topic_new(struct spa_log_topic *topic);
105 
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__)
120 
125 #define PW_LOG_TOPIC_EXTERN(var) \
126  extern struct spa_log_topic *var
127 
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__)
135 
136 #define PW_LOG_TOPIC_INIT(var) \
137  spa_log_topic_init(pw_log_get(), var);
138 
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)))
142 
143 
144 #define pw_logt(lev,topic,...) \
145 ({ \
146  if (SPA_UNLIKELY(pw_log_topic_enabled(lev,topic))) \
147  pw_log_logt(lev,topic,__FILE__,__LINE__,__func__,__VA_ARGS__); \
148 })
149 
150 #define pw_log(lev,...) pw_logt(lev,PW_LOG_TOPIC_DEFAULT,__VA_ARGS__)
151 
152 #define pw_log_error(...) pw_log(SPA_LOG_LEVEL_ERROR,__VA_ARGS__)
153 #define pw_log_warn(...) pw_log(SPA_LOG_LEVEL_WARN,__VA_ARGS__)
154 #define pw_log_info(...) pw_log(SPA_LOG_LEVEL_INFO,__VA_ARGS__)
155 #define pw_log_debug(...) pw_log(SPA_LOG_LEVEL_DEBUG,__VA_ARGS__)
156 #define pw_log_trace(...) pw_log(SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
157 
158 #define pw_logt_error(t,...) pw_logt(SPA_LOG_LEVEL_ERROR,t,__VA_ARGS__)
159 #define pw_logt_warn(t,...) pw_logt(SPA_LOG_LEVEL_WARN,t,__VA_ARGS__)
160 #define pw_logt_info(t,...) pw_logt(SPA_LOG_LEVEL_INFO,t,__VA_ARGS__)
161 #define pw_logt_debug(t,...) pw_logt(SPA_LOG_LEVEL_DEBUG,t,__VA_ARGS__)
162 #define pw_logt_trace(t,...) pw_logt(SPA_LOG_LEVEL_TRACE,t,__VA_ARGS__)
163 
164 #ifndef FASTPATH
165 #define pw_log_trace_fp(...) pw_log(SPA_LOG_LEVEL_TRACE,__VA_ARGS__)
166 #else
167 #define pw_log_trace_fp(...)
168 #endif
169 
174 #ifdef __cplusplus
175 }
176 #endif
177 #endif /* PIPEWIRE_LOG_H */
void 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) 1(6
Log a message for a topic.
void pw_log_set(struct spa_log *log)
Configure a logging module.
Definition: log.c:83
void void void void pw_log_logv(enum spa_log_level level, const char *file, int line, const char *func, const char *fmt, va_list args) 1(5
Log a message for the default topic.
struct spa_log * pw_log_get(void)
Get the log interface.
Definition: log.c:98
void pw_log_set_level(enum spa_log_level level)
Configure the logging level.
Definition: log.c:107
struct spa_log_topic * PW_LOG_TOPIC_DEFAULT
Definition: log.c:48
enum spa_log_level pw_log_level
The global log level.
Definition: log.c:43
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,...) 1(6
Log a message for a topic.
void void void pw_log_log(enum spa_log_level level, const char *file, int line, const char *func, const char *fmt,...) 1(5
Log a message for the default topic.
void void void void void _pw_log_topic_new(struct spa_log_topic *topic)
Initialize the log topic.
Definition: log.c:422
spa_log_level
Definition: log.h:65
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:260
spa/support/log.h
Identifier for a topic.
Definition: log.h:103
Definition: log.h:81
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition: log.h:90