aboutsummaryrefslogtreecommitdiffstats
path: root/include/log.h
diff options
context:
space:
mode:
authorLibravatar M Stoeckl <code@mstoeckl.com>2019-01-20 13:51:12 -0500
committerLibravatar emersion <contact@emersion.fr>2019-01-21 12:59:42 +0100
commit1211a81aad18bbc4d9e8fb9973238ad8e7e1f688 (patch)
tree5c3f60e0219cb8b4a1b7cafb760a871661866e32 /include/log.h
parentLog libinput_config_status errors (diff)
downloadsway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.tar.gz
sway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.tar.zst
sway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.zip
Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although with a sway_* prefix. (This is very similar to PR #2009.) However, the logging function no longer needs to be replaceable, so sway_log_init's second argument is used to set the exit callback for sway_abort. wlr_log_init is still invoked in sway/main.c This commit makes it easier to remove the wlroots dependency for the helper programs swaymsg, swaybg, swaybar, and swaynag.
Diffstat (limited to 'include/log.h')
-rw-r--r--include/log.h44
1 files changed, 38 insertions, 6 deletions
diff --git a/include/log.h b/include/log.h
index 6fb2f277..adf431ab 100644
--- a/include/log.h
+++ b/include/log.h
@@ -1,7 +1,18 @@
1#ifndef _SWAY_LOG_H 1#ifndef _SWAY_LOG_H
2#define _SWAY_LOG_H 2#define _SWAY_LOG_H
3
3#include <stdbool.h> 4#include <stdbool.h>
4#include <wlr/util/log.h> 5#include <stdarg.h>
6#include <string.h>
7#include <errno.h>
8
9typedef enum {
10 SWAY_SILENT = 0,
11 SWAY_ERROR = 1,
12 SWAY_INFO = 2,
13 SWAY_DEBUG = 3,
14 SWAY_LOG_IMPORTANCE_LAST,
15} sway_log_importance_t;
5 16
6#ifdef __GNUC__ 17#ifdef __GNUC__
7#define ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end))) 18#define ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end)))
@@ -9,14 +20,35 @@
9#define ATTRIB_PRINTF(start, end) 20#define ATTRIB_PRINTF(start, end)
10#endif 21#endif
11 22
23void error_handler(int sig);
24
25typedef void (*terminate_callback_t)(int exit_code);
26
27// Will log all messages less than or equal to `verbosity`
28// The `terminate` callback is called by `sway_abort`
29void sway_log_init(sway_log_importance_t verbosity, terminate_callback_t terminate);
30
31void _sway_log(sway_log_importance_t verbosity, const char *format, ...) ATTRIB_PRINTF(2, 3);
32void _sway_vlog(sway_log_importance_t verbosity, const char *format, va_list args) ATTRIB_PRINTF(2, 0);
12void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2); 33void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2);
34bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3);
35
36// TODO: get meson to precompute this, for better reproducibility/less overhead
37const char *_sway_strip_path(const char *filepath);
38
39#define sway_log(verb, fmt, ...) \
40 _sway_log(verb, "[%s:%d] " fmt, _sway_strip_path(__FILE__), __LINE__, ##__VA_ARGS__)
41
42#define sway_vlog(verb, fmt, args) \
43 _sway_vlog(verb, "[%s:%d] " fmt, _sway_strip_path(__FILE__), __LINE__, args)
44
45#define sway_log_errno(verb, fmt, ...) \
46 sway_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno))
47
13#define sway_abort(FMT, ...) \ 48#define sway_abort(FMT, ...) \
14 _sway_abort("[%s:%d] " FMT, _wlr_strip_path(__FILE__), __LINE__, ##__VA_ARGS__) 49 _sway_abort("[%s:%d] " FMT, _sway_strip_path(__FILE__), __LINE__, ##__VA_ARGS__)
15 50
16bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3);
17#define sway_assert(COND, FMT, ...) \ 51#define sway_assert(COND, FMT, ...) \
18 _sway_assert(COND, "[%s:%d] %s:" FMT, _wlr_strip_path(__FILE__), __LINE__, __func__, ##__VA_ARGS__) 52 _sway_assert(COND, "[%s:%d] %s:" FMT, _sway_strip_path(__FILE__), __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__)
19
20void error_handler(int sig);
21 53
22#endif 54#endif