From a09f2176d90da39885b7640fd4609fca19786db1 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 22 Mar 2022 12:55:17 +0100 Subject: [PATCH 1/3] message.cc: introduce MessageTypeToLogPriority In the case that normal logging is not possible, Qmsg() logs to syslog. Instead of logging with priority LOG_ERR in this case without regarding the message type, we now translate the bareos message type to a syslog priority. --- core/src/lib/message.cc | 53 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/core/src/lib/message.cc b/core/src/lib/message.cc index fa99a054f39..351ac861910 100644 --- a/core/src/lib/message.cc +++ b/core/src/lib/message.cc @@ -1531,6 +1531,57 @@ int Mmsg(std::vector& msgbuf, const char* fmt, ...) } } +// convert bareos message type to syslog log priority +static int MessageTypeToLogPriority(int message_type) +{ + { + switch (message_type) { + case M_ABORT: + return LOG_EMERG; + case M_TERM: + return LOG_EMERG; + + case M_DEBUG: + return LOG_DEBUG; + case M_FATAL: + return LOG_ALERT; + + case M_ERROR: + return LOG_ERR; + case M_ERROR_TERM: + return LOG_ERR; + + case M_WARNING: + return LOG_WARNING; + + case M_INFO: + return LOG_INFO; + case M_SAVED: + return LOG_INFO; + case M_NOTSAVED: + return LOG_INFO; + case M_SKIPPED: + return LOG_INFO; + case M_MOUNT: + return LOG_INFO; + + case M_RESTORED: + return LOG_INFO; + case M_SECURITY: + return LOG_INFO; + case M_ALERT: + return LOG_INFO; + case M_VOLMGMT: + return LOG_INFO; + case M_AUDIT: + return LOG_INFO; + + default: + return LOG_ERR; + } + } +} + /* * We queue messages rather than print them directly. This * is generally used in low level routines (msg handler, bnet) @@ -1569,7 +1620,7 @@ void Qmsg(JobControlRecord* jcr, int type, utime_t mtime, const char* fmt, ...) // If no jcr or no JobId or no queue or dequeuing send to syslog if (!jcr || !jcr->JobId || !jcr->msg_queue || jcr->dequeuing_msgs) { - syslog(LOG_DAEMON | LOG_ERR, "%s", item->msg_); + syslog(LOG_DAEMON | MessageTypeToLogPriority(type), "%s", item->msg_); free(item->msg_); item->msg_ = nullptr; free(item); From 009cbcb5180480e1ba8937b1bad95ae0e8e0b77c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 22 Mar 2022 15:46:07 +0100 Subject: [PATCH 2/3] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 043a9e935be..870e6b8441b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https: - dir: fix crash when there are no jobs to consolidate [PR #1131] ### Changed +- Qmsg: in case of syslog logging use adapted log priority instead of always LOG_ERR [PR #1134] - webui: remove an unnecessary .bvfs_get_jobids and buildSubtree() call [PR #1050] - git: set merge strategy for CHANGELOG.md to union [PR #1062] - webui: add timeline chart by jobs [PR #1059] From e4c0a76a50cfdd4f1321ac2226e6f8444b0b0058 Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Thu, 31 Mar 2022 12:06:33 +0200 Subject: [PATCH 3/3] lib: avoid duplicate syslog priority conversion Move the existing conversion for the syslog backend into the new MessageTypeToLogPriority() so we have only one common location to do the conversion. --- core/src/lib/message.cc | 115 +++++++++++++--------------------------- 1 file changed, 36 insertions(+), 79 deletions(-) diff --git a/core/src/lib/message.cc b/core/src/lib/message.cc index 351ac861910..0f8feccdd8a 100644 --- a/core/src/lib/message.cc +++ b/core/src/lib/message.cc @@ -77,6 +77,8 @@ static bool trace = false; #endif static bool hangup = false; +static int MessageTypeToLogPriority(int message_type); + /* * Walk back in a string from end looking for a * path separator. @@ -745,40 +747,8 @@ void DispatchMessage(JobControlRecord* jcr, * Dispatch based on our internal message type to a matching syslog * one. */ - switch (type) { - case M_ERROR: - case M_ERROR_TERM: - SendToSyslog(d->syslog_facility_ | LOG_ERR, msg); - break; - case M_ABORT: - case M_FATAL: - SendToSyslog(d->syslog_facility_ | LOG_CRIT, msg); - break; - case M_WARNING: - SendToSyslog(d->syslog_facility_ | LOG_WARNING, msg); - break; - case M_DEBUG: - SendToSyslog(d->syslog_facility_ | LOG_DEBUG, msg); - break; - case M_INFO: - case M_NOTSAVED: - case M_RESTORED: - case M_SAVED: - case M_SKIPPED: - case M_TERM: - SendToSyslog(d->syslog_facility_ | LOG_INFO, msg); - break; - case M_ALERT: - case M_AUDIT: - case M_MOUNT: - case M_SECURITY: - case M_VOLMGMT: - SendToSyslog(d->syslog_facility_ | LOG_NOTICE, msg); - break; - default: - SendToSyslog(d->syslog_facility_ | LOG_ERR, msg); - break; - } + SendToSyslog(d->syslog_facility_ | MessageTypeToLogPriority(type), + msg); break; case MessageDestinationCode::kOperator: Dmsg1(850, "OPERATOR for following msg: %s\n", msg); @@ -1534,51 +1504,38 @@ int Mmsg(std::vector& msgbuf, const char* fmt, ...) // convert bareos message type to syslog log priority static int MessageTypeToLogPriority(int message_type) { - { - switch (message_type) { - case M_ABORT: - return LOG_EMERG; - case M_TERM: - return LOG_EMERG; - - case M_DEBUG: - return LOG_DEBUG; - case M_FATAL: - return LOG_ALERT; - - case M_ERROR: - return LOG_ERR; - case M_ERROR_TERM: - return LOG_ERR; - - case M_WARNING: - return LOG_WARNING; - - case M_INFO: - return LOG_INFO; - case M_SAVED: - return LOG_INFO; - case M_NOTSAVED: - return LOG_INFO; - case M_SKIPPED: - return LOG_INFO; - case M_MOUNT: - return LOG_INFO; - - case M_RESTORED: - return LOG_INFO; - case M_SECURITY: - return LOG_INFO; - case M_ALERT: - return LOG_INFO; - case M_VOLMGMT: - return LOG_INFO; - case M_AUDIT: - return LOG_INFO; - - default: - return LOG_ERR; - } + switch (message_type) { + case M_ERROR: + case M_ERROR_TERM: + return LOG_ERR; + + case M_ABORT: + case M_FATAL: + return LOG_CRIT; + + case M_WARNING: + return LOG_WARNING; + + case M_DEBUG: + return LOG_DEBUG; + + case M_INFO: + case M_NOTSAVED: + case M_RESTORED: + case M_SAVED: + case M_SKIPPED: + case M_TERM: + return LOG_INFO; + + case M_ALERT: + case M_AUDIT: + case M_MOUNT: + case M_SECURITY: + case M_VOLMGMT: + return LOG_NOTICE; + + default: + return LOG_ERR; } }