X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Flog.c;h=0371e9be618eba73a315490ff3e2bcc3c3671868;hb=5ae4620a2484a390dd63642ba66fbb4ca09cbd21;hp=28b51423bbd9916face38f59ea24c8c3453b5064;hpb=c145f7e5297ef06aaf84689762a736d5bc8cbb83;p=i3%2Fi3 diff --git a/src/log.c b/src/log.c index 28b51423..0371e9be 100644 --- a/src/log.c +++ b/src/log.c @@ -1,9 +1,9 @@ /* - * vim:ts=8:expandtab + * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager * - * © 2009 Michael Stapelberg and contributors + * © 2009-2010 Michael Stapelberg and contributors * * See file LICENSE for license information. * @@ -21,40 +21,40 @@ /* loglevels.h is autogenerated at make time */ #include "loglevels.h" -static uint32_t loglevel = 0; +static uint64_t loglevel = 0; static bool verbose = true; -/** +/* * Set verbosity of i3. If verbose is set to true, informative messages will * be printed to stdout. If verbose is set to false, only errors will be * printed. * */ void set_verbosity(bool _verbose) { - verbose = _verbose; + verbose = _verbose; } -/** +/* * Enables the given loglevel. * */ void add_loglevel(const char *level) { - /* Handle the special loglevel "all" */ - if (strcasecmp(level, "all") == 0) { - loglevel = UINT32_MAX; - return; - } - - for (int i = 0; i < sizeof(loglevels) / sizeof(char*); i++) { - if (strcasecmp(loglevels[i], level) != 0) - continue; - - /* The position in the array (plus one) is the amount of times - * which we need to shift 1 to the left to get our bitmask for - * the specific loglevel. */ - loglevel |= (1 << (i+1)); - break; - } + /* Handle the special loglevel "all" */ + if (strcasecmp(level, "all") == 0) { + loglevel = UINT64_MAX; + return; + } + + for (int i = 0; i < sizeof(loglevels) / sizeof(char*); i++) { + if (strcasecmp(loglevels[i], level) != 0) + continue; + + /* The position in the array (plus one) is the amount of times + * which we need to shift 1 to the left to get our bitmask for + * the specific loglevel. */ + loglevel |= (1 << (i+1)); + break; + } } /* @@ -63,44 +63,44 @@ void add_loglevel(const char *level) { * */ void vlog(char *fmt, va_list args) { - char timebuf[64]; - - /* Get current time */ - time_t t = time(NULL); - /* Convert time to local time (determined by the locale) */ - struct tm *tmp = localtime(&t); - /* Generate time prefix */ - strftime(timebuf, sizeof(timebuf), "%x %X - ", tmp); - printf("%s", timebuf); - vprintf(fmt, args); + char timebuf[64]; + + /* Get current time */ + time_t t = time(NULL); + /* Convert time to local time (determined by the locale) */ + struct tm *tmp = localtime(&t); + /* Generate time prefix */ + strftime(timebuf, sizeof(timebuf), "%x %X - ", tmp); + printf("%s", timebuf); + vprintf(fmt, args); } -/** +/* * Logs the given message to stdout while prefixing the current time to it, * but only if verbose mode is activated. * */ void verboselog(char *fmt, ...) { - va_list args; + va_list args; - if (!verbose) - return; + if (!verbose) + return; - va_start(args, fmt); - vlog(fmt, args); - va_end(args); + va_start(args, fmt); + vlog(fmt, args); + va_end(args); } -/** +/* * Logs the given message to stdout while prefixing the current time to it. * */ void errorlog(char *fmt, ...) { - va_list args; + va_list args; - va_start(args, fmt); - vlog(fmt, args); - va_end(args); + va_start(args, fmt); + vlog(fmt, args); + va_end(args); } /* @@ -109,13 +109,13 @@ void errorlog(char *fmt, ...) { * This is to be called by DLOG() which includes filename/linenumber * */ -void debuglog(int lev, char *fmt, ...) { - va_list args; +void debuglog(uint64_t lev, char *fmt, ...) { + va_list args; - if ((loglevel & lev) == 0) - return; + if ((loglevel & lev) == 0) + return; - va_start(args, fmt); - vlog(fmt, args); - va_end(args); + va_start(args, fmt); + vlog(fmt, args); + va_end(args); }