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