Skip to content

Commit

Permalink
Merge pull request #1134
Browse files Browse the repository at this point in the history
Qmsg: in case of syslog logging use adapted log priority instead of always LOG_ERR
  • Loading branch information
arogge committed Apr 5, 2022
2 parents 8bffdaf + e4c0a76 commit 552914f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -41,6 +41,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- FreeBSD packages: add missing ddl/update 2171_2192 and 2192_2210 files [PR #1147]

### 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]
Expand Down
78 changes: 43 additions & 35 deletions core/src/lib/message.cc
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1531,6 +1501,44 @@ int Mmsg(std::vector<char>& msgbuf, const char* fmt, ...)
}
}

// convert bareos message type to syslog log priority
static int MessageTypeToLogPriority(int message_type)
{
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;
}
}

/*
* We queue messages rather than print them directly. This
* is generally used in low level routines (msg handler, bnet)
Expand Down Expand Up @@ -1569,7 +1577,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);
Expand Down

0 comments on commit 552914f

Please sign in to comment.