Commit cc6a574f6a3e1c611925acf31eb8afcc6a1382a6 Parent: ede0f0208b7827bc2bc3ebb7e91a503d256cf3d7 Author: mcol <mcol@posteo.net> Date: 2021-01-18 21:33:42 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-01-18 22:59:02 +0000 Add log handling, printing all log messages to stdout
src/log.h Added
@@ -0,0 +1,6 @@ +#ifndef DESKWM_LOG_H +#define DESKWM_LOG_H + +void init_log(enum wlr_log_importance log_level); + +#endif
src/log.c Added
@@ -0,0 +1,36 @@ +#include <stdio.h> +#include <time.h> +#include <wlr/util/log.h> + + +enum wlr_log_importance log_importance; + + +const char *verbosity_headers[] = { + [WLR_SILENT] = "", + [WLR_ERROR] = "[ERROR]", + [WLR_INFO] = "[INFO]", + [WLR_DEBUG] = "[DEBUG]", +}; + + +void log_stdout(enum wlr_log_importance verbosity, const char *fmt, va_list args) { + if (verbosity > log_importance) { + return; + } + + time_t t = time(NULL); + struct tm *now = localtime(&t); + char nows[20]; + strftime(nows, 20, "%F %T", now); + + fprintf(stdout, "%s %s: ", nows, verbosity_headers[verbosity]); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); +} + + +void init_log(enum wlr_log_importance log_level) { + log_importance = log_level; + wlr_log_init(log_importance, log_stdout); +}
src/deskwm.c Modified
@@ -13,6 +13,7 @@ #include "config.h" #include "deskwm.h" #include "input.h" +#include "log.h" #include "output.h" #include "shell.h" #include "types.h" @@ -27,12 +28,13 @@ ; -int main(int argc, char *argv[]) { - wlr_log_init(WLR_ERROR, NULL); - +int main(int argc, char *argv[]) +{ int opt; + int log_level = WLR_ERROR; char *config = NULL; - while ((opt = getopt(argc, argv, "hcdi:")) != -1) { + + while ((opt = getopt(argc, argv, "hcdi")) != -1) { switch (opt) { case 'h': printf(usage); @@ -42,14 +44,16 @@ config = strdup(optarg); break; case 'd': - wlr_log_init(WLR_DEBUG, NULL); + log_level = WLR_DEBUG; break; case 'i': - wlr_log_init(WLR_INFO, NULL); + log_level = WLR_INFO; break; } } + init_log(log_level); + // create struct server server; server.display = wl_display_create();