>From 6ead0ef2bc361fa7e0a292709922133aeb3776b3 Mon Sep 17 00:00:00 2001
From: Sven Göthel <[email protected]>
Date: Mon, 20 Jul 2026 02:19:24 +0200
Subject: Refine log-level usage, define values
diff --git a/cache.c b/cache.c
index 7f11fa7..8165f48 100644
--- a/cache.c
+++ b/cache.c
@@ -120,7 +120,7 @@ static int sendslot_to_minrate(time_t tStart, time_t tNow,
size_t off,
static int sendslot_ok(time_t tStart, time_t tNow, size_t size,
struct cache_slot *slot)
{
- if (ctx.cfg.log_level > 90) {
+ if (ctx.cfg.log_level >= LOG_LVL_DBG) {
const time_t td_total = tNow - tStart;
const long rate = size / MY_MAX(1, td_total);
cache_log("[cgit] send_slot status: sent cache %s (%s) %ld
bytes) to "
@@ -134,7 +134,7 @@ static int sendslot_ok(time_t tStart, time_t tNow, size_t
size,
static int sendslot_ok2(time_t tStart, size_t size, struct cache_slot *slot)
{
- if (ctx.cfg.log_level > 90) {
+ if (ctx.cfg.log_level >= LOG_LVL_DBG) {
return sendslot_ok(tStart, time(NULL), size, slot);
}
return 0;
@@ -329,7 +329,7 @@ static int lock_slot(struct cache_slot *slot, time_t tStart)
++wait_count;
usleep(100000); // 100ms sleep instead of sched_yield()
}
- if (wait_count && ctx.cfg.log_level > 90) {
+ if (wait_count && ctx.cfg.log_level >= LOG_LVL_DBG) {
cache_log("[cgit] Lock: Waited %ds (%zu tries, cache_fd %d) to
lock slot %s (%s)\n",
(int)(time(NULL) - tStart), wait_count,
slot->cache_fd,
slot->lock_name, slot->key);
@@ -338,7 +338,7 @@ static int lock_slot(struct cache_slot *slot, time_t tStart)
int err = open_slot(slot);
if (!err && slot->match) {
// concurrent process wrote the file
- if (ctx.cfg.log_level > 50) {
+ if (ctx.cfg.log_level >= LOG_LVL_WARN) {
cache_log("[cgit] Lock: Concurrent produced
slot %s (%s)\n",
slot->lock_name, slot->key);
}
@@ -366,7 +366,7 @@ static int lock_slot(struct cache_slot *slot, time_t tStart)
close_lock(slot);
return saved_errno;
}
- if (ctx.cfg.log_level > 90) {
+ if (ctx.cfg.log_level >= LOG_LVL_DBG) {
cache_log("[cgit] Lock (%ds): Successful locked slot %s (%s)\n",
(int)(time(NULL) - tStart), slot->lock_name,
slot->key);
}
@@ -397,7 +397,7 @@ static int unlock_slot(struct cache_slot *slot, enum
lock_file_op_t lock_file_op
err = errno;
}
}
- if (ctx.cfg.log_level < 90 && ENOENT == err) {
+ if (ctx.cfg.log_level < LOG_LVL_DBG && ENOENT == err) {
err = 0; // suppress ENOENT messages
}
if (err) {
@@ -426,7 +426,7 @@ static int unlock_slot(struct cache_slot *slot, enum
lock_file_op_t lock_file_op
}
}
if (!err) {
- if (ctx.cfg.log_level > 90) {
+ if (ctx.cfg.log_level >= LOG_LVL_DBG) {
cache_log("[cgit] Unlock: Successful unlocked slot %s
(%s)\n",
slot->lock_name, slot->key);
}
diff --git a/cgit.c b/cgit.c
index 83665ca..dc5e41c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1096,7 +1096,7 @@ int cmd_main(int argc, const char **argv)
cgit_parse_args(argc, argv);
parse_configfile(expand_macros(ctx.env.cgit_config), config_cb);
- if (ctx.cfg.log_level)
+ if (ctx.cfg.log_level >= LOG_LVL_VERBOSE)
print_config(stderr, "[cgit] init: ");
ctx.repo = NULL;
http_parse_querystring(ctx.qry.raw, querystring_cb);
diff --git a/cgit.h b/cgit.h
index df6a6c1..2691fb3 100644
--- a/cgit.h
+++ b/cgit.h
@@ -193,6 +193,10 @@ struct cgit_query {
char *vpath;
};
+typedef enum {
+ LOG_LVL_ERR=0, LOG_LVL_WARN=50, LOG_LVL_DBG=75, LOG_LVL_VERBOSE=100
+} log_level_t;
+
struct cgit_config {
int log_level; ///< defaults to zero
char *agefile;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index de25244..0c40561 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -474,8 +474,11 @@ virtual-root::
same kind of virtual urls, so this option will probably be deprecated.
log-level::
- Specifies the logging level. Above zero adds verbose logging.
- Default value: "0".
+ Specifies the logging level.
+ Zero only logs errors (LOG_LVL_ERR), greater-equal 50 adds warnings
(LOG_LVL_WARN),
+ greater-equal 75 adds debug messages
+ and greater-equal 100 adds verbose information (LOG_LVL_VERBOSE).
+ Default value: "0" (error logging only).
REPOSITORY SETTINGS
-------------------