PipeWire 0.3.36
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
42/* static */ inline SPA_PRINTF_FUNC(6, 0) void spa_log_impl_logv(void *object,
43 enum spa_log_level level,
44 const char *file,
45 int line,
46 const char *func,
47 const char *fmt,
48 va_list args)
49{
50 static const char * const levels[] = { "-", "E", "W", "I", "D", "T" };
51
52 const char *basename = strrchr(file, '/');
53 char text[512], location[1024];
54
55 if (basename)
56 basename += 1; /* skip '/' */
57 else
58 basename = file; /* use whole string if no '/' is found */
59
60 vsnprintf(text, sizeof(text), fmt, args);
61 snprintf(location, sizeof(location), "[%s][%s:%i %s()] %s\n",
62 levels[level], basename, line, func, text);
63 fputs(location, stderr);
64}
65/* static */ inline SPA_PRINTF_FUNC(6,7) void spa_log_impl_log(void *object,
66 enum spa_log_level level,
67 const char *file,
68 int line,
69 const char *func,
70 const char *fmt, ...)
71{
72 va_list args;
73 va_start(args, fmt);
74 spa_log_impl_logv(object, level, file, line, func, fmt, args);
75 va_end(args);
76}
77
78#define SPA_LOG_IMPL_DEFINE(name) \
79struct { \
80 struct spa_log log; \
81 struct spa_log_methods methods; \
82} name
83
84#define SPA_LOG_IMPL_INIT(name) \
85 { { { SPA_TYPE_INTERFACE_Log, SPA_VERSION_LOG, \
86 SPA_CALLBACKS_INIT(&name.methods, &name) }, \
87 SPA_LOG_LEVEL_INFO, }, \
88 { SPA_VERSION_LOG_METHODS, \
89 spa_log_impl_log, \
90 spa_log_impl_logv,} }
91
92#define SPA_LOG_IMPL(name) \
93 SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT(name)
94
99#ifdef __cplusplus
100} /* extern "C" */
101#endif
102#endif /* SPA_LOG_IMPL_H */
spa_log_level
Definition: build/doc/spa/support/log.h:46
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:65
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:42
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:206