PipeWire 0.3.65
spa/include/spa/debug/log.h
Go to the documentation of this file.
1/* Simple Plugin API
2 *
3 * Copyright © 2022 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_DEBUG_LOG_H
26#define SPA_DEBUG_LOG_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdio.h>
33#include <stdarg.h>
34
35#include <spa/utils/defs.h>
36#include <spa/support/log.h>
37#include <spa/debug/context.h>
38
44struct spa_debug_log_ctx {
46 struct spa_log *log;
48 const struct spa_log_topic *topic;
49 const char *file;
50 int line;
51 const char *func;
52};
55static inline void spa_debug_log_log(struct spa_debug_context *ctx, const char *fmt, ...)
57 struct spa_debug_log_ctx *c = (struct spa_debug_log_ctx*)ctx;
58 va_list args;
59 va_start(args, fmt);
60 spa_log_logtv(c->log, c->level, c->topic, c->file, c->line, c->func, fmt, args);
61 va_end(args);
62}
63
64#define SPA_LOGF_DEBUG_INIT(_l,_lev,_t,_file,_line,_func) \
65 (struct spa_debug_log_ctx){ { spa_debug_log_log }, _l, _lev, _t, \
66 _file, _line, _func }
67
68#define SPA_LOGT_DEBUG_INIT(_l,_lev,_t) \
69 SPA_LOGF_DEBUG_INIT(_l,_lev,_t,__FILE__,__LINE__,__func__)
70
71#define SPA_LOG_DEBUG_INIT(l,lev) \
72 SPA_LOGT_DEBUG_INIT(l,lev,SPA_LOG_TOPIC_DEFAULT)
74#define spa_debug_log_pod(l,lev,indent,info,pod) \
75({ \
76 struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \
77 if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \
78 spa_debugc_pod(&c.ctx, indent, info, pod); \
79})
80
81#define spa_debug_log_format(l,lev,indent,info,format) \
82({ \
83 struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \
84 if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \
85 spa_debugc_format(&c.ctx, indent, info, format); \
86})
87
88#define spa_debug_log_mem(l,lev,indent,data,len) \
89({ \
90 struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \
91 if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \
92 spa_debugc_mem(&c.ctx, indent, data, len); \
93})
94
99#ifdef __cplusplus
100} /* extern "C" */
101#endif
102
103#endif /* SPA_DEBUG_LOG_H */
spa/utils/defs.h
static void spa_debug_log_log(struct spa_debug_context *ctx, const char *fmt,...)
Definition: spa/include/spa/debug/log.h:60
spa_log_level
Definition: spa/include/spa/support/log.h:65
#define spa_log_logtv(l, lev, topic,...)
Definition: spa/include/spa/support/log.h:268
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:289
spa/debug/context.h
spa/support/log.h
Definition: spa/include/spa/debug/context.h:53
Definition: spa/include/spa/debug/log.h:49
const char * func
Definition: spa/include/spa/debug/log.h:56
int line
Definition: spa/include/spa/debug/log.h:55
struct spa_log * log
Definition: spa/include/spa/debug/log.h:51
enum spa_log_level level
Definition: spa/include/spa/debug/log.h:52
struct spa_debug_context ctx
Definition: spa/include/spa/debug/log.h:50
const char * file
Definition: spa/include/spa/debug/log.h:54
const struct spa_log_topic * topic
Definition: spa/include/spa/debug/log.h:53
Identifier for a topic.
Definition: spa/include/spa/support/log.h:103
Definition: spa/include/spa/support/log.h:81