PipeWire: log.h Source File

PipeWire 0.1.8

log.h
Go to the documentation of this file.
1 /* PipeWire
2 * Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef __PIPEWIRE_LOG_H__
21 #define __PIPEWIRE_LOG_H__
22
23 #include <spa/support/log.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
39 extern enum spa_log_level pw_log_level;
40
41 void pw_log_set(struct spa_log *log);
42 struct spa_log *pw_log_get(void);
43
44 void
45 pw_log_set_level(enum spa_log_level level);
46
47
48 void
49 pw_log_log(enum spa_log_level level,
50 const char *file,
51 int line, const char *func,
52 const char *fmt, ...) SPA_PRINTF_FUNC(5, 6);
53
54 void
55 pw_log_logv(enum spa_log_level level,
56 const char *file,
57 int line, const char *func,
58 const char *fmt, va_list args) SPA_PRINTF_FUNC(5, 0);
59
60
62 #define pw_log_level_enabled(lev) (pw_log_level >= (lev))
63
64 #if __STDC_VERSION__ >= 199901L
65
66 #define pw_log_logc(lev,...) \
67 if (SPA_UNLIKELY(pw_log_level_enabled (lev))) \
68 pw_log_log(lev,__VA_ARGS__)
69
70 #define pw_log_error(...) pw_log_logc(SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
71 #define pw_log_warn(...) pw_log_logc(SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__)
72 #define pw_log_info(...) pw_log_logc(SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__)
73 #define pw_log_debug(...) pw_log_logc(SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__)
74 #define pw_log_trace(...) pw_log_logc(SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
75
76 #else
77
78 #include <stdarg.h>
79
80 #define PW_LOG_FUNC(name,lev) \
81 static inline void pw_log_##name (const char *format, ...) SPA_PRINTF_FUNC(1, 0); \
82 { \
83 if (SPA_UNLIKELY(pw_log_level_enabled(lev))) { \
84 va_list varargs; \
85 va_start(varargs, format); \
86 pw_log_logv(lev,__FILE__,__LINE__,__func__,format,varargs); \
87 va_end(varargs); \
88 } \
89 }
90
91 PW_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR)
92 PW_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN)
93 PW_LOG_FUNC(info, SPA_LOG_LEVEL_INFO)
94 PW_LOG_FUNC(debug, SPA_LOG_LEVEL_DEBUG)
95 PW_LOG_FUNC(trace, SPA_LOG_LEVEL_TRACE)
96
97 #endif
98
99 #ifdef __cplusplus
100 }
101 #endif
102 #endif /* __PIPEWIRE_LOG_H__ */
pw_log::pw_log_set
void pw_log_set(struct spa_log *log)
Set the global log interface.
Definition: log.c:32
PW_LOG_FUNC
#define PW_LOG_FUNC(name, lev)
Definition: log.h:80
pw_log::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 with va_list.
Definition: log.c:95
pw_log::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.
Definition: log.c:70
pw_log::pw_log_get
struct spa_log * pw_log_get(void)
Get the global log interface.
Definition: log.c:43
pw_log::pw_log_set_level
void pw_log_set_level(enum spa_log_level level)
Set the global log level.
Definition: log.c:52
pw_log_level
enum spa_log_level pw_log_level
The global log level.
Definition: log.c:24