mirror of
https://github.com/swaywm/sway.git
synced 2026-04-29 06:46:22 -04:00
Merge 40d67b13d9 into 8f67903909
This commit is contained in:
commit
4b55a9d325
3 changed files with 14 additions and 35 deletions
38
common/log.c
38
common/log.c
|
|
@ -8,13 +8,11 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stringop.h>
|
#include <stringop.h>
|
||||||
|
|
||||||
int colored = 1;
|
static int colored = 1;
|
||||||
log_importance_t loglevel_default = L_ERROR;
|
static log_importance_t loglevel_default = L_ERROR;
|
||||||
log_importance_t v = L_SILENT;
|
static log_importance_t v = L_SILENT;
|
||||||
|
|
||||||
static const char *verbosity_colors[] = {
|
static const char *verbosity_colors[] = {
|
||||||
[L_SILENT] = "",
|
[L_SILENT] = "",
|
||||||
|
|
@ -38,6 +36,10 @@ void set_log_level(log_importance_t verbosity) {
|
||||||
v = verbosity;
|
v = verbosity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_importance_t get_log_level(void) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
void reset_log_level(void) {
|
void reset_log_level(void) {
|
||||||
v = loglevel_default;
|
v = loglevel_default;
|
||||||
}
|
}
|
||||||
|
|
@ -90,32 +92,6 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sway_log_errno(log_importance_t verbosity, char* format, ...) {
|
|
||||||
if (verbosity <= v) {
|
|
||||||
unsigned int c = verbosity;
|
|
||||||
if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
|
|
||||||
c = sizeof(verbosity_colors) / sizeof(char *) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (colored && isatty(STDERR_FILENO)) {
|
|
||||||
fprintf(stderr, "%s", verbosity_colors[c]);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
fprintf(stderr, ": ");
|
|
||||||
fprintf(stderr, "%s", strerror(errno));
|
|
||||||
|
|
||||||
if (colored && isatty(STDERR_FILENO)) {
|
|
||||||
fprintf(stderr, "\x1B[0m");
|
|
||||||
}
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _sway_assert(bool condition, const char* format, ...) {
|
bool _sway_assert(bool condition, const char* format, ...) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef _SWAY_LOG_H
|
#ifndef _SWAY_LOG_H
|
||||||
#define _SWAY_LOG_H
|
#define _SWAY_LOG_H
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
L_SILENT = 0,
|
L_SILENT = 0,
|
||||||
|
|
@ -11,11 +13,11 @@ typedef enum {
|
||||||
|
|
||||||
void init_log(log_importance_t verbosity);
|
void init_log(log_importance_t verbosity);
|
||||||
void set_log_level(log_importance_t verbosity);
|
void set_log_level(log_importance_t verbosity);
|
||||||
|
log_importance_t get_log_level(void);
|
||||||
void reset_log_level(void);
|
void reset_log_level(void);
|
||||||
// returns whether debug logging is on after switching.
|
// returns whether debug logging is on after switching.
|
||||||
bool toggle_debug_logging(void);
|
bool toggle_debug_logging(void);
|
||||||
void sway_log_colors(int mode);
|
void sway_log_colors(int mode);
|
||||||
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)));
|
void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
|
||||||
|
|
||||||
bool _sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
|
bool _sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
|
||||||
|
|
@ -32,6 +34,9 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const
|
||||||
_sway_log(NULL, 0, VERBOSITY, FMT, ##__VA_ARGS__)
|
_sway_log(NULL, 0, VERBOSITY, FMT, ##__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define sway_log_errno(VERBOSITY, FMT, ...) \
|
||||||
|
_sway_log(NULL, 0, VERBOSITY, FMT ": %s", ##__VA_ARGS__, strerror(errno))
|
||||||
|
|
||||||
void error_handler(int sig);
|
void error_handler(int sig);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@
|
||||||
#include <stringop.h>
|
#include <stringop.h>
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
|
|
||||||
extern log_importance_t v;
|
|
||||||
|
|
||||||
/* XXX:DEBUG:XXX */
|
/* XXX:DEBUG:XXX */
|
||||||
static void container_log(const swayc_t *c, int depth) {
|
static void container_log(const swayc_t *c, int depth) {
|
||||||
fprintf(stderr, "focus:%c",
|
fprintf(stderr, "focus:%c",
|
||||||
|
|
@ -49,7 +47,7 @@ static void container_log(const swayc_t *c, int depth) {
|
||||||
fprintf(stderr, "name:%.16s\n", c->name);
|
fprintf(stderr, "name:%.16s\n", c->name);
|
||||||
}
|
}
|
||||||
void layout_log(const swayc_t *c, int depth) {
|
void layout_log(const swayc_t *c, int depth) {
|
||||||
if (L_DEBUG > v) return;
|
if (L_DEBUG > get_log_level()) return;
|
||||||
int i, d;
|
int i, d;
|
||||||
int e = c->children ? c->children->length : 0;
|
int e = c->children ? c->children->length : 0;
|
||||||
container_log(c, depth);
|
container_log(c, depth);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue