Commit 4eb06917 authored by Steven Murray's avatar Steven Murray
Browse files

To increase maintainability I have moved the truncation of a syslog message

that exceeds the permitted maximum of syslog from the
LoggerImplementation::logMsg() method to the
LoggerImplementation::reducedSyslog() method.  I have done this because the
reducedSyslog() method is the one that does the actual work of sending the log
message syslog via a send() over a local UNIX socket.
parent b648202a
......@@ -284,16 +284,7 @@ void castor::log::LoggerImplementation::logMsg(
// Terminate the string
logMsg << "\n";
// If the message is too long for syslog then truncate it before calling
// reducedSyslog
if(logMsg.str().length() > m_maxMsgLen) {
std::ostringstream truncatedLogMsg;
truncatedLogMsg << logMsg.str().substr(0, m_maxMsgLen - 1);
truncatedLogMsg << "\n";
reducedSyslog(truncatedLogMsg.str());
} else {
reducedSyslog(logMsg.str());
}
reducedSyslog(logMsg.str());
}
//-----------------------------------------------------------------------------
......@@ -377,8 +368,14 @@ std::string castor::log::LoggerImplementation::cleanString(const std::string &s,
//-----------------------------------------------------------------------------
// reducedSyslog
//-----------------------------------------------------------------------------
void castor::log::LoggerImplementation::reducedSyslog(const std::string &msg)
void castor::log::LoggerImplementation::reducedSyslog(std::string msg)
throw() {
// Truncate the log message if it exceeds the permitted maximum
if(msg.length() > m_maxMsgLen) {
msg.resize(m_maxMsgLen);
msg[msg.length() - 1] = '\n';
}
int send_flags = 0;
#ifndef __APPLE__
// MAC has has no MSG_NOSIGNAL
......
......@@ -232,7 +232,7 @@ private:
*
* @param msg The message to be logged.
*/
void reducedSyslog(const std::string &msg) throw();
void reducedSyslog(std::string msg) throw();
/**
* Closes the connection to syslog.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment