Browse Source

feat: Make systemd priority markers conditional based on detection

- Modify levelToSystemdPriority() to only include priority markers when running under systemd
- Prevents <6> markers from appearing in logs when not running in systemd environment
- Improves log readability for non-systemd deployments
- Builds on previous systemd detection functionality (commit 2a948a6)

Testing performed:
- Verified logs show priority markers when JOURNAL_STREAM is set
- Verified logs omit priority markers when not running under systemd
- Tested both scenarios with test programs
Fszontagh 3 months ago
parent
commit
426270c50e
1 changed files with 5 additions and 0 deletions
  1. 5 0
      src/logger.cpp

+ 5 - 0
src/logger.cpp

@@ -95,6 +95,11 @@ std::string Logger::typeToString(LoggerType type) {
 }
 }
 
 
 std::string Logger::levelToSystemdPriority(LogLevel level) {
 std::string Logger::levelToSystemdPriority(LogLevel level) {
+    // Only include priority markers when running under systemd
+    if (!isRunningUnderSystemd()) {
+        return "";
+    }
+    
     // systemd journal priority levels:
     // systemd journal priority levels:
     // 0=emerg, 1=alert, 2=crit, 3=err, 4=warning, 5=notice, 6=info, 7=debug
     // 0=emerg, 1=alert, 2=crit, 3=err, 4=warning, 5=notice, 6=info, 7=debug
     switch (level) {
     switch (level) {