PipeWire: spa/support/log-impl.h Source File

PipeWire 0.3.50

log-impl.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_IMPL_H
26#define SPA_LOG_IMPL_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdio.h>
33
34#include <spa/utils/type.h>
35#include <spa/support/log.h>
36
42static inline SPA_PRINTF_FUNC(7, 0) void spa_log_impl_logtv(void *object,
43 enum spa_log_level level,
44 const struct spa_log_topic *topic,
45 const char *file,
46 int line,
47 const char *func,
48 const char *fmt,
49 va_list args)
50{
51 static const char * const levels[] = { "-", "E", "W", "I", "D", "T" };
52
53 const char *basename = strrchr(file, '/');
54 char text[512], location[1024];
55 char topicstr[32] = {0};
56
57 if (basename)
58 basename += 1; /* skip '/' */
59 else
60 basename = file; /* use whole string if no '/' is found */
61
62 if (topic && topic->topic)
63 snprintf(topicstr, sizeof(topicstr), " %s ", topic->topic);
64 vsnprintf(text, sizeof(text), fmt, args);
65 snprintf(location, sizeof(location), "[%s]%s[%s:%i %s()] %s\n",
66 levels[level],
67 topicstr,
68 basename, line, func, text);
69 fputs(location, stderr);
70}
71
72static inline SPA_PRINTF_FUNC(7,8) void spa_log_impl_logt(void *object,
73 enum spa_log_level level,
74 const struct spa_log_topic *topic,
75 const char *file,
76 int line,
77 const char *func,
78 const char *fmt, ...)
79{
80 va_list args;
81 va_start(args, fmt);
82 spa_log_impl_logtv(object, level, topic, file, line, func, fmt, args);
83 va_end(args);
84}
85
86static inline SPA_PRINTF_FUNC(6, 0) void spa_log_impl_logv(void *object,
87 enum spa_log_level level,
88 const char *file,
89 int line,
90 const char *func,
91 const char *fmt,
92 va_list args)
93{
94
95 spa_log_impl_logtv(object, level, NULL, file, line, func, fmt, args);
96}
97
98static inline SPA_PRINTF_FUNC(6,7) void spa_log_impl_log(void *object,
99 enum spa_log_level level,
100 const char *file,
101 int line,
102 const char *func,
103 const char *fmt, ...)
104{
105 va_list args;
106 va_start(args, fmt);
107 spa_log_impl_logv(object, level, file, line, func, fmt, args);
108 va_end(args);
109}
110
111static inline void spa_log_impl_topic_init(void *object, struct spa_log_topic *topic)
112{
113 /* noop */
114}
115
116#define SPA_LOG_IMPL_DEFINE(name) \
117struct { \
118 struct spa_log log; \
119 struct spa_log_methods methods; \
120} name
121
122#define SPA_LOG_IMPL_INIT(name) \
123 { { { SPA_TYPE_INTERFACE_Log, SPA_VERSION_LOG, \
124 SPA_CALLBACKS_INIT(&name.methods, &name) }, \
125 SPA_LOG_LEVEL_INFO, }, \
126 { SPA_VERSION_LOG_METHODS, \
127 spa_log_impl_log, \
128 spa_log_impl_logv, \
129 spa_log_impl_logt, \
130 spa_log_impl_logtv, \
131 } }
132
133#define SPA_LOG_IMPL(name) \
134 SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT(name)
135
140#ifdef __cplusplus
141} /* extern "C" */
142#endif
143#endif /* SPA_LOG_IMPL_H */
spa_log_level
spa_log_level
Definition: log.h:65
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:103
spa_log_impl_topic_init
static void spa_log_impl_topic_init(void *object, struct spa_log_topic *topic)
Definition: log-impl.h:116
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:47
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:77
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:91
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:260
log.h
spa/support/log.h
type.h
spa/utils/type.h
spa_log_topic
Identifier for a topic.
Definition: log.h:103