PipeWire 1.4.8

Loading...
Searching...
No Matches
log-impl.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_LOG_IMPL_H
6#define SPA_LOG_IMPL_H
7
8#ifdef __cplusplus
9 extern "C" {
10#endif
11
12#include <stdio.h>
13
14#include <spa/utils/type.h>
15#include <spa/support/log.h>
16
21
22 static inline SPA_PRINTF_FUNC(7, 0) void spa_log_impl_logtv(void *object SPA_UNUSED,
23 enum spa_log_level level,
24 const struct spa_log_topic *topic,
25 const char *file,
26 int line,
27 const char *func,
28 const char *fmt,
29 va_list args)
30{
31 static const char * const levels[] = { "-", "E", "W", "I", "D", "T" };
32
33 const char *basename = strrchr(file, '/');
34 char text[512], location[1024];
35 char topicstr[32] = {0};
36
37 if (basename)
38 basename += 1; /* skip '/' */
39 else
40 basename = file; /* use whole string if no '/' is found */
41
42 if (topic && topic->topic)
43 snprintf(topicstr, sizeof(topicstr), " %s ", topic->topic);
44 vsnprintf(text, sizeof(text), fmt, args);
45 snprintf(location, sizeof(location), "[%s]%s[%s:%i %s()] %s\n",
46 levels[level],
47 topicstr,
48 basename, line, func, text);
49 fputs(location, stderr);
50}
51
52 static inline SPA_PRINTF_FUNC(7,8) void spa_log_impl_logt(void *object,
53 enum spa_log_level level,
54 const struct spa_log_topic *topic,
55 const char *file,
56 int line,
57 const char *func,
58 const char *fmt, ...)
59{
60 va_list args;
61 va_start(args, fmt);
62 spa_log_impl_logtv(object, level, topic, file, line, func, fmt, args);
63 va_end(args);
64}
65
66 static inline SPA_PRINTF_FUNC(6, 0) void spa_log_impl_logv(void *object,
67 enum spa_log_level level,
68 const char *file,
69 int line,
70 const char *func,
71 const char *fmt,
72 va_list args)
73{
74
75 spa_log_impl_logtv(object, level, NULL, file, line, func, fmt, args);
76}
77
78 static inline SPA_PRINTF_FUNC(6,7) void spa_log_impl_log(void *object,
79 enum spa_log_level level,
80 const char *file,
81 int line,
82 const char *func,
83 const char *fmt, ...)
84{
85 va_list args;
86 va_start(args, fmt);
87 spa_log_impl_logv(object, level, file, line, func, fmt, args);
88 va_end(args);
89}
90
91 static inline void spa_log_impl_topic_init(void *object SPA_UNUSED, struct spa_log_topic *topic SPA_UNUSED)
92{
93 /* noop */
94}
95
96#define SPA_LOG_IMPL_DEFINE(name) \
97 struct { \
98 struct spa_log log; \
99 struct spa_log_methods methods; \
100} name
101
102#define SPA_LOG_IMPL_INIT(name) \
103 { { { SPA_TYPE_INTERFACE_Log, SPA_VERSION_LOG, \
104 SPA_CALLBACKS_INIT(&(name).methods, &(name)) }, \
105 SPA_LOG_LEVEL_INFO, }, \
106 { SPA_VERSION_LOG_METHODS, \
107 spa_log_impl_log, \
108 spa_log_impl_logv, \
109 spa_log_impl_logt, \
110 spa_log_impl_logtv, \
111 spa_log_impl_topic_init, \
112 } }
113
114#define SPA_LOG_IMPL(name) \
115 SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT(name)
116
118
119 */
120
121#ifdef __cplusplus
122} /* extern "C" */
123#endif
124#endif /* SPA_LOG_IMPL_H */
args
uint32_t int int const char va_list args
Definition core.h:434
va_end
va_end(args)
vsnprintf
vsnprintf(buffer, sizeof(buffer), message, args)
va_start
va_start(args, message)
spa_log_level
spa_log_level
Definition log.h:55
spa_log_impl_log
static void spa_log_impl_log(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt,...)
Definition log-impl.h:83
spa_log_impl_logtv
static void spa_log_impl_logtv(void *object, enum spa_log_level level, const struct spa_log_topic *topic, const char *file, int line, const char *func, const char *fmt, va_list args)
Definition log-impl.h:27
spa_log_impl_logt
static void spa_log_impl_logt(void *object, enum spa_log_level level, const struct spa_log_topic *topic, const char *file, int line, const char *func, const char *fmt,...)
Definition log-impl.h:57
spa_log_impl_logv
static void spa_log_impl_logv(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt, va_list args)
Definition log-impl.h:71
spa_log_impl_topic_init
static void spa_log_impl_topic_init(void *object, struct spa_log_topic *topic 1)
Definition log-impl.h:96
SPA_UNUSED
#define SPA_UNUSED
Definition defs.h:307
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:295
log.h
spa/support/log.h
type.h
spa/utils/type.h
spa_log_topic
Identifier for a topic.
Definition log.h:93