mirror of
https://github.com/swaywm/sway.git
synced 2024-11-28 02:41:28 +00:00
changed logging
This commit is contained in:
parent
aaa0923bc4
commit
ed470d1a59
|
@ -12,13 +12,16 @@ typedef enum {
|
|||
|
||||
void init_log(log_importance_t verbosity);
|
||||
void sway_log_colors(int mode);
|
||||
void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3)));
|
||||
void sway_log_func(log_importance_t verbosity, const char *func, const char* format, ...) __attribute__((format(printf,3,4)));
|
||||
void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3)));
|
||||
void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
|
||||
bool sway_assert_func(bool condition, const char *func, const char* format, ...) __attribute__((format(printf,3,4)));
|
||||
|
||||
#define sway_log(V, FMT, ...) \
|
||||
sway_log_func(V, __PRETTY_FUNCTION__, FMT, ##__VA_ARGS__)
|
||||
|
||||
bool _sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
|
||||
#define sway_assert(COND, FMT, ...) \
|
||||
_sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
|
||||
sway_assert_func(COND, __PRETTY_FUNCTION__, FMT, ##__VA_ARGS__)
|
||||
|
||||
void error_handler(int sig);
|
||||
|
||||
|
|
17
sway/log.c
17
sway/log.c
|
@ -20,6 +20,14 @@ static const char *verbosity_colors[] = {
|
|||
"\x1B[1;30m", // L_DEBUG
|
||||
};
|
||||
|
||||
static const char *log_str[] = {
|
||||
[L_SILENT] = "Msg",
|
||||
[L_DEBUG] = "Debug",
|
||||
[L_INFO] = "Info",
|
||||
[L_ERROR] = "Error",
|
||||
};
|
||||
|
||||
|
||||
void init_log(log_importance_t verbosity) {
|
||||
v = verbosity;
|
||||
signal(SIGSEGV, error_handler);
|
||||
|
@ -40,7 +48,7 @@ void sway_abort(const char *format, ...) {
|
|||
sway_terminate();
|
||||
}
|
||||
|
||||
void sway_log(log_importance_t verbosity, const char* format, ...) {
|
||||
void sway_log_func(log_importance_t verbosity, const char *func, const char* format, ...) {
|
||||
if (verbosity <= v) {
|
||||
unsigned int c = verbosity;
|
||||
if (c > sizeof(verbosity_colors) / sizeof(char *)) {
|
||||
|
@ -48,7 +56,8 @@ void sway_log(log_importance_t verbosity, const char* format, ...) {
|
|||
}
|
||||
|
||||
if (colored && isatty(STDERR_FILENO)) {
|
||||
fprintf(stderr, "%s", verbosity_colors[c]);
|
||||
fprintf(stderr, "%s%-5s| %-32s | ", verbosity_colors[c],
|
||||
log_str[verbosity], func);
|
||||
}
|
||||
|
||||
va_list args;
|
||||
|
@ -91,14 +100,14 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) {
|
|||
}
|
||||
}
|
||||
|
||||
bool _sway_assert(bool condition, const char* format, ...) {
|
||||
bool sway_assert_func(bool condition, const char *func, const char *format, ...) {
|
||||
if (condition) {
|
||||
return true;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
sway_log(L_ERROR, format, args);
|
||||
sway_log_func(L_ERROR, func, format, args);
|
||||
va_end(args);
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
|
Loading…
Reference in a new issue