2015-08-09 07:01:22 +10:00
|
|
|
#ifndef _SWAY_LOG_H
|
|
|
|
#define _SWAY_LOG_H
|
2019-01-21 05:51:12 +11:00
|
|
|
|
2015-08-19 07:38:34 +10:00
|
|
|
#include <stdbool.h>
|
2019-01-21 05:51:12 +11:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SWAY_SILENT = 0,
|
|
|
|
SWAY_ERROR = 1,
|
|
|
|
SWAY_INFO = 2,
|
|
|
|
SWAY_DEBUG = 3,
|
|
|
|
SWAY_LOG_IMPORTANCE_LAST,
|
|
|
|
} sway_log_importance_t;
|
2017-04-21 02:13:53 +10:00
|
|
|
|
2018-07-10 07:54:30 +10:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end)))
|
|
|
|
#else
|
|
|
|
#define ATTRIB_PRINTF(start, end)
|
|
|
|
#endif
|
|
|
|
|
2019-01-21 05:51:12 +11:00
|
|
|
void error_handler(int sig);
|
|
|
|
|
|
|
|
typedef void (*terminate_callback_t)(int exit_code);
|
|
|
|
|
|
|
|
// Will log all messages less than or equal to `verbosity`
|
|
|
|
// The `terminate` callback is called by `sway_abort`
|
|
|
|
void sway_log_init(sway_log_importance_t verbosity, terminate_callback_t terminate);
|
|
|
|
|
|
|
|
void _sway_log(sway_log_importance_t verbosity, const char *format, ...) ATTRIB_PRINTF(2, 3);
|
|
|
|
void _sway_vlog(sway_log_importance_t verbosity, const char *format, va_list args) ATTRIB_PRINTF(2, 0);
|
2018-01-06 09:36:32 +11:00
|
|
|
void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2);
|
2019-01-21 05:51:12 +11:00
|
|
|
bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3);
|
|
|
|
|
2019-06-23 13:13:19 +10:00
|
|
|
#ifdef SWAY_REL_SRC_DIR
|
|
|
|
// strip prefix from __FILE__, leaving the path relative to the project root
|
|
|
|
#define _SWAY_FILENAME ((const char *)__FILE__ + sizeof(SWAY_REL_SRC_DIR) - 1)
|
|
|
|
#else
|
|
|
|
#define _SWAY_FILENAME __FILE__
|
|
|
|
#endif
|
2019-01-21 05:51:12 +11:00
|
|
|
|
|
|
|
#define sway_log(verb, fmt, ...) \
|
2019-06-23 13:13:19 +10:00
|
|
|
_sway_log(verb, "[%s:%d] " fmt, _SWAY_FILENAME, __LINE__, ##__VA_ARGS__)
|
2019-01-21 05:51:12 +11:00
|
|
|
|
|
|
|
#define sway_vlog(verb, fmt, args) \
|
2019-06-23 13:13:19 +10:00
|
|
|
_sway_vlog(verb, "[%s:%d] " fmt, _SWAY_FILENAME, __LINE__, args)
|
2019-01-21 05:51:12 +11:00
|
|
|
|
|
|
|
#define sway_log_errno(verb, fmt, ...) \
|
|
|
|
sway_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno))
|
|
|
|
|
2017-04-21 02:13:53 +10:00
|
|
|
#define sway_abort(FMT, ...) \
|
2019-06-23 13:13:19 +10:00
|
|
|
_sway_abort("[%s:%d] " FMT, _SWAY_FILENAME, __LINE__, ##__VA_ARGS__)
|
2015-08-27 04:01:26 +10:00
|
|
|
|
|
|
|
#define sway_assert(COND, FMT, ...) \
|
2019-06-23 13:13:19 +10:00
|
|
|
_sway_assert(COND, "[%s:%d] %s:" FMT, _SWAY_FILENAME, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__)
|
2015-08-09 07:01:22 +10:00
|
|
|
|
|
|
|
#endif
|