PipeWire 1.0.3
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
9extern "C" {
10#endif
11
12#include <stdio.h>
13
14#include <spa/utils/type.h>
15#include <spa/support/log.h>
16
22static 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
52static 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
66static 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
78static 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
91static 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) \
97struct { \
98 struct spa_log log; \
99 struct spa_log_methods methods; \
100} name
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 } }
112
113#define SPA_LOG_IMPL(name) \
114 SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT(name)
115
120#ifdef __cplusplus
121} /* extern "C" */
122#endif
123#endif /* SPA_LOG_IMPL_H */
spa_log_level
Definition log.h:45
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
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
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
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
static void spa_log_impl_topic_init(void *object, struct spa_log_topic *topic 1)
Definition log-impl.h:96
#define SPA_UNUSED
Definition defs.h:289
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:277
spa/support/log.h
spa/utils/type.h
Identifier for a topic.
Definition log.h:83