aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2026-05-11 23:37:51 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2026-05-11 23:37:51 -0400
commit18ebe00bfcd377bda01e1ce70a339cbd6008658d (patch)
treec2e29dbc0d2056879d2cb5b9821e41123a791476
parent1944c5281a29fa02d21338129445dba23d01cc52 (diff)
downloadstasis-18ebe00bfcd377bda01e1ce70a339cbd6008658d.tar.gz
Give log messages variable verbosity
* WARN = Show only the preface and message * INFO = Show preface, function, and message * DEBUG = Show preface, source file, line number, function, and message
-rw-r--r--src/lib/core/log.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/lib/core/log.c b/src/lib/core/log.c
index aea3231..b1cab4c 100644
--- a/src/lib/core/log.c
+++ b/src/lib/core/log.c
@@ -42,19 +42,38 @@ void log_print_debug(const struct ExecPoint ep, const char *fmt, ...) {
int log_msgv(FILE *stream, const struct ExecPoint ep, const char *preface_color, const char *preface, const char *fmt, va_list ap) {
char header[STASIS_BUFSIZ] = {0};
+ const int no_info = LOG_LEVEL < LOG_LEVEL_INFO;
+ const int some_info = LOG_LEVEL < LOG_LEVEL_DEBUG;
int len = snprintf(header, sizeof(header),
STASIS_COLOR_RESET
"%s%s: "
- STASIS_COLOR_RESET
- STASIS_COLOR_WHITE
- "%s:%d: %s(): "
STASIS_COLOR_RESET,
preface_color ? preface_color : STASIS_COLOR_RED,
- preface ? preface : "UNKNOWN",
- path_basename((char *) ep.file),
- ep.line,
- ep.function);
+ preface ? preface : "UNKNOWN");
+
+ if (no_info) {
+ len += snprintf(header + strlen(header), sizeof(header) - len,
+ STASIS_COLOR_WHITE
+ ""
+ STASIS_COLOR_RESET);
+ } else if (some_info) {
+ len += snprintf(header + strlen(header), sizeof(header) - len,
+ STASIS_COLOR_WHITE
+ "%s(): "
+ STASIS_COLOR_RESET,
+ ep.function);
+ } else {
+ // everything
+ len += snprintf(header + strlen(header), sizeof(header) - len,
+ STASIS_COLOR_WHITE
+ "%s:%d: %s(): "
+ STASIS_COLOR_RESET,
+ path_basename((char *) ep.file),
+ ep.line,
+ ep.function);
+ }
+
if (len >= (int) sizeof(header)) {
SYSERROR("header format truncated (%d >= %d)", len, (int) sizeof(header));
return len;