log.h
Go to the documentation of this file.
/* Simple Plugin API
*
* Copyright © 2018 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SPA_LOG_H
#define SPA_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
#include <spa/utils/type.h>
#include <spa/utils/defs.h>
#include <spa/utils/hook.h>
#define SPA_LOG_TOPIC_DEFAULT NULL
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,
};
#define SPA_TYPE_INTERFACE_Log SPA_TYPE_INFO_INTERFACE_BASE "Log"
struct spa_log {
#define SPA_VERSION_LOG 0
struct spa_interface iface;
enum spa_log_level level;
};
struct spa_log_topic {
#define SPA_VERSION_LOG_TOPIC 0
uint32_t version;
const char *topic;
enum spa_log_level level;
bool has_custom_level;
};
struct spa_log_methods {
#define SPA_VERSION_LOG_METHODS 1
uint32_t version;
void (*log) (void *object,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
void (*logv) (void *object,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt,
va_list args) SPA_PRINTF_FUNC(6, 0);
void (*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, ...) SPA_PRINTF_FUNC(7, 8);
void (*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) SPA_PRINTF_FUNC(7, 0);
void (*topic_init) (void *object, struct spa_log_topic *topic);
};
#define SPA_LOG_TOPIC(v, t) \
(struct spa_log_topic){ .version = v, .topic = (t)}
#define spa_log_topic_init(l, topic) \
do { \
struct spa_log *_l = l; \
if (SPA_LIKELY(_l)) { \
struct spa_interface *_if = &_l->iface; \
spa_interface_call(_if, struct spa_log_methods, \
topic_init, 1, topic); \
} \
} while(0)
/* Unused, left for backwards compat */
#define spa_log_level_enabled(l,lev) ((l) && (l)->level >= (lev))
#define spa_log_level_topic_enabled(l,topic,lev) \
({ \
struct spa_log *_log = l; \
enum spa_log_level _lev = _log ? _log->level : SPA_LOG_LEVEL_NONE; \
struct spa_log_topic *_t = (struct spa_log_topic *)topic; \
if (_t && _t->has_custom_level) \
_lev = _t->level; \
_lev >= lev; \
})
/* Transparently calls to version 0 log if v1 is not supported */
#define spa_log_logt(l,lev,topic,...) \
({ \
struct spa_log *_l = l; \
struct spa_interface *_if = &_l->iface; \
if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
if (!spa_interface_call(_if, \
struct spa_log_methods, logt, 1, \
lev, topic, \
__VA_ARGS__)) \
spa_interface_call(_if, \
struct spa_log_methods, log, 0, \
lev, __VA_ARGS__); \
} \
})
/* Transparently calls to version 0 logv if v1 is not supported */
#define spa_log_logtv(l,lev,topic,...) \
({ \
struct spa_log *_l = l; \
struct spa_interface *_if = &_l->iface; \
if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \
if (!spa_interface_call(_if, \
struct spa_log_methods, logtv, 1, \
lev, topic, \
__VA_ARGS__)) \
spa_interface_call(_if, \
struct spa_log_methods, logv, 0, \
lev, __VA_ARGS__); \
} \
})
#define spa_log_log(l,lev,...) \
spa_log_logt(l,lev,SPA_LOG_TOPIC_DEFAULT,__VA_ARGS__)
#define spa_log_logv(l,lev,...) \
spa_log_logtv(l,lev,SPA_LOG_TOPIC_DEFAULT,__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__)
#define spa_logt_error(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_ERROR,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define spa_logt_warn(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_WARN,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define spa_logt_info(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_INFO,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define spa_logt_debug(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_DEBUG,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define spa_logt_trace(l,t,...) spa_log_logt(l,SPA_LOG_LEVEL_TRACE,t,__FILE__,__LINE__,__func__,__VA_ARGS__)
#ifndef FASTPATH
#define spa_log_trace_fp(l,...) spa_log_log(l,SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
#else
#define spa_log_trace_fp(l,...)
#endif
#define SPA_KEY_LOG_LEVEL "log.level"
#define SPA_KEY_LOG_COLORS "log.colors"
#define SPA_KEY_LOG_FILE "log.file"
#define SPA_KEY_LOG_TIMESTAMP "log.timestamp"
#define SPA_KEY_LOG_LINE "log.line"
#define SPA_KEY_LOG_PATTERNS "log.patterns"
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_LOG_H */
defs.h
spa/utils/defs.h
spa_log_level
spa_log_level
Definition: log.h:65
SPA_LOG_LEVEL_INFO
@ SPA_LOG_LEVEL_INFO
Definition: log.h:69
SPA_LOG_LEVEL_NONE
@ SPA_LOG_LEVEL_NONE
Definition: log.h:66
SPA_LOG_LEVEL_TRACE
@ SPA_LOG_LEVEL_TRACE
Definition: log.h:71
SPA_LOG_LEVEL_DEBUG
@ SPA_LOG_LEVEL_DEBUG
Definition: log.h:70
SPA_LOG_LEVEL_ERROR
@ SPA_LOG_LEVEL_ERROR
Definition: log.h:67
SPA_LOG_LEVEL_WARN
@ SPA_LOG_LEVEL_WARN
Definition: log.h:68
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:260
hook.h
spa/utils/hook.h
type.h
spa/utils/type.h
spa_interface
Definition: hook.h:158
spa_log_methods
Definition: log.h:117
spa_log_methods::logt
void(*) void(*) void(* 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,...) 1(7
Log a message with the given log level for the given topic.
Definition: log.h:182
spa_log_methods::version
uint32_t version
Definition: log.h:120
spa_log_methods::topic_init
void(*) void(*) void(*) void(*) void(* topic_init)(void *object, struct spa_log_topic *topic)
Initializes a spa_log_topic to the correct logging level.
Definition: log.h:221
spa_log_methods::logv
void(*) void(* logv)(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt, va_list args) 1(6
Log a message with the given log level.
Definition: log.h:158
spa_log_methods::log
void(* log)(void *object, enum spa_log_level level, const char *file, int line, const char *func, const char *fmt,...) 1(6
Log a message with the given log level.
Definition: log.h:136
spa_log_methods::logtv
void(*) void(*) void(*) void(* 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) 1(7
Log a message with the given log level for the given topic.
Definition: log.h:207
spa_log_topic
Identifier for a topic.
Definition: log.h:103
spa_log_topic::version
uint32_t version
the version of this topic.
Definition: log.h:108
spa_log_topic::has_custom_level
bool has_custom_level
False if this topic follows the Log level.
Definition: log.h:114
spa_log_topic::level
enum spa_log_level level
Logging level set for this topic.
Definition: log.h:112
spa_log_topic::topic
const char * topic
The string identifier for the topic.
Definition: log.h:110
spa_log
Definition: log.h:81
spa_log::iface
struct spa_interface iface
Definition: log.h:86
spa_log::level
enum spa_log_level level
Logging level, everything above this level is not logged.
Definition: log.h:90