]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
logging: add log severity to file log prefix when debug is enabled
authorLuke Valenta <lvalenta@cloudflare.com>
Wed, 1 Nov 2023 20:32:45 +0000 (16:32 -0400)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 7 Nov 2023 14:43:57 +0000 (15:43 +0100)
logging.c

index 22c326c0e7f68dd5aba99728e09a9a458dc18dda..b929fcbd94757ed9cac9f5fec01f3ad8ab471617 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -68,6 +68,9 @@ static struct LogFile logfiles[MAX_FILELOGS];
 /* Global prefix for debug messages */
 static char *debug_prefix;
 
+/* Log severity to character mapping (debug, info, warn, err, fatal) */
+static const char severity_chars[LOGS_FATAL - LOGS_DEBUG + 1] = {'D', 'I', 'W', 'E', 'F'};
+
 /* ================================================== */
 /* Init function */
 
@@ -145,6 +148,7 @@ void LOG_Message(LOG_Severity severity,
   struct tm *tm;
 
   assert(initialised);
+  severity = CLAMP(LOGS_DEBUG, severity, LOGS_FATAL);
 
   if (!system_log && file_log && severity >= log_min_severity) {
     /* Don't clutter up syslog with timestamps and internal debugging info */
@@ -156,7 +160,8 @@ void LOG_Message(LOG_Severity severity,
     }
 #if DEBUG > 0
     if (log_min_severity <= LOGS_DEBUG)
-      fprintf(file_log, "%s%s:%d:(%s) ", debug_prefix, filename, line_number, function_name);
+      fprintf(file_log, "%c:%s%s:%d:(%s) ", severity_chars[severity - LOGS_DEBUG],
+              debug_prefix, filename, line_number, function_name);
 #endif
   }