PipeWire 0.3.35
build/doc/spa/support/log.h
Go to the documentation of this file.
1/* Simple Plugin API
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 SPA_LOG_H
26#define SPA_LOG_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdarg.h>
33
34#include <spa/utils/type.h>
35#include <spa/utils/defs.h>
36#include <spa/utils/hook.h>
37
53};
54
58#define SPA_TYPE_INTERFACE_Log SPA_TYPE_INFO_INTERFACE_BASE "Log"
59
60
61struct spa_log {
64#define SPA_VERSION_LOG 0
70};
71
73#define SPA_VERSION_LOG_METHODS 0
74 uint32_t version;
86 void (*log) (void *object,
87 enum spa_log_level level,
88 const char *file,
89 int line,
90 const char *func,
91 const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
92
104 void (*logv) (void *object,
105 enum spa_log_level level,
106 const char *file,
107 int line,
108 const char *func,
109 const char *fmt,
110 va_list args) SPA_PRINTF_FUNC(6, 0);
111};
112
113#define spa_log_level_enabled(l,lev) ((l) && (l)->level >= (lev))
114
115#if defined(__USE_ISOC11) || defined(__USE_ISOC99) || \
116 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
117
118#define spa_log_log(l,lev,...) \
119({ \
120 struct spa_log *_l = l; \
121 if (SPA_UNLIKELY(spa_log_level_enabled(_l, lev))) \
122 spa_interface_call(&_l->iface, \
123 struct spa_log_methods, log, 0, lev, \
124 __VA_ARGS__); \
125})
126
127#define spa_log_logv(l,lev,...) \
128({ \
129 struct spa_log *_l = l; \
130 if (SPA_UNLIKELY(spa_log_level_enabled(_l, lev))) \
131 spa_interface_call(&_l->iface, \
132 struct spa_log_methods, logv, 0, lev, \
133 __VA_ARGS__); \
134})
135
136#define spa_log_error(l,...) spa_log_log(l,SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
137#define spa_log_warn(l,...) spa_log_log(l,SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__)
138#define spa_log_info(l,...) spa_log_log(l,SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__)
139#define spa_log_debug(l,...) spa_log_log(l,SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__)
140#define spa_log_trace(l,...) spa_log_log(l,SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
141
142#ifndef FASTPATH
143#define spa_log_trace_fp(l,...) spa_log_log(l,SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
144#else
145#define spa_log_trace_fp(l,...)
146#endif
147
148#else
149
150#define SPA_LOG_FUNC(name,lev) \
151/* static */ inline SPA_PRINTF_FUNC(2,3) void spa_log_##name (struct spa_log *l, const char *format, ...) \
152{ \
153 if (SPA_UNLIKELY(spa_log_level_enabled(l, lev))) { \
154 va_list varargs; \
155 va_start (varargs, format); \
156 spa_interface_call(&l->iface, \
157 struct spa_log_methods, logv, 0, lev, \
158 __FILE__,__LINE__,__func__,format,varargs); \
159 va_end (varargs); \
160 } \
161}
162
163SPA_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR)
164SPA_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN)
165SPA_LOG_FUNC(info, SPA_LOG_LEVEL_INFO)
166SPA_LOG_FUNC(debug, SPA_LOG_LEVEL_DEBUG)
167SPA_LOG_FUNC(trace, SPA_LOG_LEVEL_TRACE)
168
169#ifndef FASTPATH
170SPA_LOG_FUNC(trace_fp, SPA_LOG_LEVEL_TRACE)
171#else
172/* static */ inline void spa_log_trace_fp (struct spa_log *l, const char *format, ...) { }
173#endif
174
175#endif
176
180#define SPA_KEY_LOG_LEVEL "log.level"
181#define SPA_KEY_LOG_COLORS "log.colors"
182#define SPA_KEY_LOG_FILE "log.file"
184#define SPA_KEY_LOG_TIMESTAMP "log.timestamp"
185#define SPA_KEY_LOG_LINE "log.line"
191#ifdef __cplusplus
192} /* extern "C" */
193#endif
194#endif /* SPA_LOG_H */
spa_log_level
Definition: build/doc/spa/support/log.h:46
#define spa_log_trace_fp(l,...)
Definition: build/doc/spa/support/log.h:143
@ SPA_LOG_LEVEL_INFO
Definition: build/doc/spa/support/log.h:50
@ SPA_LOG_LEVEL_NONE
Definition: build/doc/spa/support/log.h:47
@ SPA_LOG_LEVEL_TRACE
Definition: build/doc/spa/support/log.h:52
@ SPA_LOG_LEVEL_DEBUG
Definition: build/doc/spa/support/log.h:51
@ SPA_LOG_LEVEL_ERROR
Definition: build/doc/spa/support/log.h:48
@ SPA_LOG_LEVEL_WARN
Definition: build/doc/spa/support/log.h:49
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:206
Definition: hook.h:146
Definition: build/doc/spa/support/log.h:72
uint32_t version
Definition: build/doc/spa/support/log.h:74
void(*) void(* logv)(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt, va_list args) 1(6
Log a message with the given log level.
Definition: build/doc/spa/support/log.h:104
void(* log)(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt,...) 1(6
Log a message with the given log level.
Definition: build/doc/spa/support/log.h:86
Definition: build/doc/spa/support/log.h:61
struct spa_interface iface
Definition: build/doc/spa/support/log.h:65
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition: build/doc/spa/support/log.h:69