PipeWire  0.3.66
spa/include/spa/debug/log.h
Go to the documentation of this file.
1 /* Simple Plugin API */
2 /* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4 
5 #ifndef SPA_DEBUG_LOG_H
6 #define SPA_DEBUG_LOG_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <stdio.h>
13 #include <stdarg.h>
14 
15 #include <spa/utils/defs.h>
16 #include <spa/support/log.h>
17 #include <spa/debug/context.h>
18 
24 struct spa_debug_log_ctx {
25  struct spa_debug_context ctx;
26  struct spa_log *log;
27  enum spa_log_level level;
28  const struct spa_log_topic *topic;
29  const char *file;
30  int line;
31  const char *func;
32 };
33 
35 static inline void spa_debug_log_log(struct spa_debug_context *ctx, const char *fmt, ...)
36 {
37  struct spa_debug_log_ctx *c = (struct spa_debug_log_ctx*)ctx;
38  va_list args;
39  va_start(args, fmt);
40  spa_log_logtv(c->log, c->level, c->topic, c->file, c->line, c->func, fmt, args);
41  va_end(args);
42 }
43 
44 #define SPA_LOGF_DEBUG_INIT(_l,_lev,_t,_file,_line,_func) \
45  (struct spa_debug_log_ctx){ { spa_debug_log_log }, _l, _lev, _t, \
46  _file, _line, _func }
47 
48 #define SPA_LOGT_DEBUG_INIT(_l,_lev,_t) \
49  SPA_LOGF_DEBUG_INIT(_l,_lev,_t,__FILE__,__LINE__,__func__)
50 
51 #define SPA_LOG_DEBUG_INIT(l,lev) \
52  SPA_LOGT_DEBUG_INIT(l,lev,SPA_LOG_TOPIC_DEFAULT)
53 
54 #define spa_debug_log_pod(l,lev,indent,info,pod) \
55 ({ \
56  struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \
57  if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \
58  spa_debugc_pod(&c.ctx, indent, info, pod); \
59 })
60 
61 #define spa_debug_log_format(l,lev,indent,info,format) \
62 ({ \
63  struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \
64  if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \
65  spa_debugc_format(&c.ctx, indent, info, format); \
66 })
67 
68 #define spa_debug_log_mem(l,lev,indent,data,len) \
69 ({ \
70  struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \
71  if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \
72  spa_debugc_mem(&c.ctx, indent, data, len); \
73 })
74 
79 #ifdef __cplusplus
80 } /* extern "C" */
81 #endif
82 
83 #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:40
spa_log_level
Definition: spa/include/spa/support/log.h:45
#define spa_log_logtv(l, lev, topic,...)
Definition: spa/include/spa/support/log.h:248
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:269
spa/debug/context.h
spa/support/log.h
Definition: spa/include/spa/debug/context.h:33
Definition: spa/include/spa/debug/log.h:29
const char * func
Definition: spa/include/spa/debug/log.h:36
int line
Definition: spa/include/spa/debug/log.h:35
struct spa_log * log
Definition: spa/include/spa/debug/log.h:31
enum spa_log_level level
Definition: spa/include/spa/debug/log.h:32
struct spa_debug_context ctx
Definition: spa/include/spa/debug/log.h:30
const char * file
Definition: spa/include/spa/debug/log.h:34
const struct spa_log_topic * topic
Definition: spa/include/spa/debug/log.h:33
Identifier for a topic.
Definition: spa/include/spa/support/log.h:83
Definition: spa/include/spa/support/log.h:61