44ceea7 ยท 1 month ago 7 commits
 1#ifndef _SWAYLOCK_LOG_H
 2#define _SWAYLOCK_LOG_H
 3
 4#include <stdarg.h>
 5#include <string.h>
 6#include <errno.h>
 7
 8enum log_importance {
 9	LOG_SILENT = 0,
10	LOG_ERROR = 1,
11	LOG_INFO = 2,
12	LOG_DEBUG = 3,
13	LOG_TRACE = 4,
14	LOG_IMPORTANCE_LAST,
15};
16
17void swaylock_log_init(enum log_importance verbosity);
18
19#ifdef __GNUC__
20#define _ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end)))
21#else
22#define _ATTRIB_PRINTF(start, end)
23#endif
24
25void _swaylock_log(enum log_importance verbosity, const char *format, ...)
26	_ATTRIB_PRINTF(2, 3);
27
28void _swaylock_trace(const char *file, int line, const char *func);
29
30const char *_swaylock_strip_path(const char *filepath);
31
32#define swaylock_log(verb, fmt, ...) \
33	_swaylock_log(verb, "[%s:%d] " fmt, _swaylock_strip_path(__FILE__), \
34			__LINE__, ##__VA_ARGS__)
35
36#define swaylock_log_errno(verb, fmt, ...) \
37	swaylock_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno))
38
39#define swaylock_trace() \
40	_swaylock_trace(__FILE__, __LINE__, __func__)
41
42#endif