pipewire/spa/include/spa/log.h
Wim Taymans 1acba78234 API cleanups
Fix docs
Add some more versions to interfaces
Make types for the various proxy object + inline methods that does type
checking and create proxys etc.
Set owner client of client-nodes in the properties
Pass type to bind to in create-node
Don't place global id in the info structs
Improve registration of marshal functions
Pass more types around as ids
2017-07-18 10:06:40 +02:00

146 lines
4 KiB
C

/* Simple Plugin API
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __SPA_LOG_H__
#define __SPA_LOG_H__
#ifdef __cplusplus
extern "C" {
#endif
#define SPA_TYPE__Log SPA_TYPE_INTERFACE_BASE "Log"
#define SPA_TYPE_LOG_BASE SPA_TYPE__Log ":"
#include <stdarg.h>
#include <spa/defs.h>
#include <spa/plugin.h>
#include <spa/loop.h>
enum spa_log_level {
SPA_LOG_LEVEL_NONE = 0,
SPA_LOG_LEVEL_ERROR,
SPA_LOG_LEVEL_WARN,
SPA_LOG_LEVEL_INFO,
SPA_LOG_LEVEL_DEBUG,
SPA_LOG_LEVEL_TRACE,
};
/**
* struct spa_log:
*
* The Log interface
*/
struct spa_log {
/* the version of this log. This can be used to expand this
* structure in the future */
#define SPA_VERSION_LOG 0
uint32_t version;
/**
* struct spa_log::info
*
* Extra information about the log
*/
const struct spa_dict *info;
/**
* struct spa_log::level
*
* Logging level, everything above this level is not logged
*/
enum spa_log_level level;
/**
* struct spa_log::log
* @log: a #struct spa_log
* @level: a #enum spa_log_level
* @file: the file name
* @line: the line number
* @func: the function name
* @fmt: printf style format
* @...: format arguments
*
* Log a message with the given log level.
*/
void (*log) (struct spa_log *log,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
/**
* struct spa_log::logv
* @log: a #struct spa_log
* @level: a #enum spa_log_level
* @file: the file name
* @line: the line number
* @func: the function name
* @fmt: printf style format
* @args: format arguments
*
* Log a message with the given log level.
*/
void (*logv) (struct spa_log *log,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt,
va_list args) SPA_PRINTF_FUNC(6, 0);
};
#define spa_log_level_enabled(l,lev) ((l) && (l)->level >= (lev))
#if __STDC_VERSION__ >= 199901L
#define spa_log_log(l,lev,...) \
if (SPA_UNLIKELY (spa_log_level_enabled (l, lev))) \
(l)->log((l),lev,__VA_ARGS__)
#define spa_log_error(l,...) spa_log_log(l,SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define spa_log_warn(l,...) spa_log_log(l,SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define spa_log_info(l,...) spa_log_log(l,SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define spa_log_debug(l,...) spa_log_log(l,SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define spa_log_trace(l,...) spa_log_log(l,SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
#else
#define SPA_LOG_FUNC(name,lev) \
static inline void spa_log_##name (struct spa_log *l, const char *format, ...) \
{ \
if (SPA_UNLIKELY (spa_log_level_enabled (l, lev))) { \
va_list varargs; \
va_start (varargs, format); \
(l)->logv((l),lev,__FILE__,__LINE__,__func__,format,varargs); \
va_end (varargs); \
} \
}
SPA_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR)
SPA_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN)
SPA_LOG_FUNC(info, SPA_LOG_LEVEL_INFO)
SPA_LOG_FUNC(debug, SPA_LOG_LEVEL_DEBUG)
SPA_LOG_FUNC(trace, SPA_LOG_LEVEL_TRACE)
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_LOG_H__ */