4 * i3 - an improved dynamic tiling window manager
6 * © 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
10 * src/log.c: handles the setting of loglevels, contains the logging functions.
21 /* loglevels.h is autogenerated at make time */
22 #include "loglevels.h"
24 static uint64_t loglevel = 0;
25 static bool verbose = true;
28 * Set verbosity of i3. If verbose is set to true, informative messages will
29 * be printed to stdout. If verbose is set to false, only errors will be
33 void set_verbosity(bool _verbose) {
38 * Enables the given loglevel.
41 void add_loglevel(const char *level) {
42 /* Handle the special loglevel "all" */
43 if (strcasecmp(level, "all") == 0) {
44 loglevel = UINT64_MAX;
48 for (int i = 0; i < sizeof(loglevels) / sizeof(char*); i++) {
49 if (strcasecmp(loglevels[i], level) != 0)
52 /* The position in the array (plus one) is the amount of times
53 * which we need to shift 1 to the left to get our bitmask for
54 * the specific loglevel. */
55 loglevel |= (1 << (i+1));
61 * Logs the given message to stdout while prefixing the current time to it.
62 * This is to be called by *LOG() which includes filename/linenumber/function.
65 void vlog(char *fmt, va_list args) {
68 /* Get current time */
69 time_t t = time(NULL);
70 /* Convert time to local time (determined by the locale) */
71 struct tm *tmp = localtime(&t);
72 /* Generate time prefix */
73 strftime(timebuf, sizeof(timebuf), "%x %X - ", tmp);
74 printf("%s", timebuf);
79 * Logs the given message to stdout while prefixing the current time to it,
80 * but only if verbose mode is activated.
83 void verboselog(char *fmt, ...) {
95 * Logs the given message to stdout while prefixing the current time to it.
98 void errorlog(char *fmt, ...) {
107 * Logs the given message to stdout while prefixing the current time to it,
108 * but only if the corresponding debug loglevel was activated.
109 * This is to be called by DLOG() which includes filename/linenumber
112 void debuglog(uint64_t lev, char *fmt, ...) {
115 if ((loglevel & lev) == 0)