diff --git a/src/helpers.c b/src/helpers.c index e97dade0..f0d04677 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -39,8 +39,6 @@ #include "private.h" #include "utmp-api.h" -int _slup = 0; /* INTERNAL: Is syslog up yet? */ - char *strip_line(char *line) { char *ptr; diff --git a/src/log.c b/src/log.c index e8b9c05c..d88ba85c 100644 --- a/src/log.c +++ b/src/log.c @@ -21,6 +21,7 @@ * THE SOFTWARE. */ +#include "config.h" #include #include #include @@ -46,6 +47,7 @@ void log_toggle_debug(void) void logit(int prio, const char *fmt, ...) { va_list ap; + static int _slup = 0; va_start(ap, fmt); if (!_slup && !fexist("/dev/log")) { diff --git a/src/log.h b/src/log.h index 3c056059..aa3aebd8 100644 --- a/src/log.h +++ b/src/log.h @@ -24,24 +24,21 @@ #ifndef FINIT_LOG_H_ #define FINIT_LOG_H_ -#include -#include /* strerror() */ #include /* - * Error and debug messages + * Developer error and debug messages, otherwise --> use logit() <-- + * ~~~~~~~~~~~ + * All of these prepend the function, so only use for critical warnings + * errors and debug messages. For all other user messages, see logit() * - * Use of logit() is preferred, but these are guaranteed to display on - * /dev/console as well. Useful for critical errors and early debug. + * The default log level is LOG_NOTICE. To toggle LOG_DEBUG messages, + * use `initctl debug` or add `--debug` to the kernel cmdline. */ -#define _l(prio, fmt, args...) do { if (_slup) warnx(fmt, ##args); logit(prio, fmt "\n", ##args); } while (0) -#define _m(prio, fmt, args...) do { _l(prio, "%s() - " fmt, __func__, ##args); } while (0) -#define _d(fmt, args...) do { if (debug) { _m(LOG_DEBUG, fmt, ##args); } } while (0) -#define _w(fmt, args...) do { _m(LOG_WARNING, fmt, ##args); } while (0) -#define _e(fmt, args...) do { _m(LOG_ERR, fmt, ##args); } while (0) -#define _pe(fmt, args...) do { _m(LOG_ERR, fmt ". Error %d: %s", ##args, errno, strerror(errno)); } while (0) - -extern int _slup; /* INTERNAL: Is syslog up yet? */ +#define _d(fmt, args...) logit(LOG_DEBUG, "%s():" fmt, __func__, ##args) +#define _w(fmt, args...) logit(LOG_WARNING, "%s():" fmt, __func__, ##args) +#define _e(fmt, args...) logit(LOG_ERR, "%s():" fmt, __func__, ##args) +#define _pe(fmt, args...) logit(LOG_ERR, "%s():" fmt ": %m", __func__, ##args) void log_toggle_debug(void); void logit (int prio, const char *fmt, ...);