Skip to content
Snippets Groups Projects
Commit 4381e93d authored by Steven Murray's avatar Steven Murray
Browse files

castor::log::LoggerImplementation now implements a log mask

parent 2c20bac7
Branches
Tags
No related merge requests found
......@@ -48,7 +48,8 @@ castor::log::LoggerImplementation::LoggerImplementation(
m_maxMsgLen(determineMaxMsgLen()),
m_logFile(-1),
m_connected(false),
m_priorityToText(generatePriorityToTextMap()) {
m_priorityToText(generatePriorityToTextMap()),
m_configTextToPriority(generateConfigTextToPriorityMap()) {
initMutex();
}
......@@ -122,6 +123,34 @@ std::map<int, std::string>
return m;
}
//------------------------------------------------------------------------------
// generateConfigTextToPriorityMap
//------------------------------------------------------------------------------
std::map<std::string, int>
castor::log::LoggerImplementation::generateConfigTextToPriorityMap() const
throw(castor::exception::Internal) {
std::map<std::string, int> m;
try {
m["LOG_EMERG"] = LOG_EMERG;
m["LOG_ALERT"] = LOG_ALERT;
m["LOG_CRIT"] = LOG_CRIT;
m["LOG_ERR"] = LOG_ERR;
m["LOG_WARNING"] = LOG_WARNING;
m["LOG_NOTICE"] = LOG_NOTICE;
m["LOG_INFO"] = LOG_INFO;
m["LOG_DEBUG"] = LOG_DEBUG;
} catch(std::exception &se) {
castor::exception::Internal ex;
ex.getMessage() <<
"Failed to generate configuration text to priority mapping: " <<
se.what();
throw ex;
}
return m;
}
//------------------------------------------------------------------------------
// initMutex
//------------------------------------------------------------------------------
......@@ -465,3 +494,27 @@ void castor::log::LoggerImplementation::operator() (
Param *emptyParams = NULL;
operator() (priority, msg, 0, emptyParams);
}
//------------------------------------------------------------------------------
// logMask
//------------------------------------------------------------------------------
int castor::log::LoggerImplementation::logMask() const throw() {
const char *const p = getconfent("LogMask", m_programName.c_str(), 0);
// If the configuration file defines the log mask to use
if (p != NULL) {
// Try to find the corresponding integer priority value
std::map<std::string, int>::const_iterator itor =
m_configTextToPriority.find(p);
// Return the priority if it was found else return the default INFO level
if(m_configTextToPriority.end() != itor) {
return itor->second;
} else {
return LOG_INFO;
}
}
// If the priority wasn't found, default is INFO level
return LOG_INFO;
}
......@@ -251,6 +251,17 @@ private:
*/
const std::map<int, std::string> m_priorityToText;
/**
* Map from the possible string values of the LogMask parameters of
* /etc/castor.conf and their equivalent syslog priorities.
*/
const std::map<std::string, int> m_configTextToPriority;
/**
* Returns the log mask for the program.
*/
int logMask() const throw();
/**
* Determines the maximum message length that the client syslog server can
* handle.
......@@ -267,6 +278,14 @@ private:
std::map<int, std::string> generatePriorityToTextMap() const
throw(castor::exception::Internal);
/**
* Generates and returns the mapping between the possible string values
* of the LogMask parameters of /etc/castor.conf and their equivalent
* syslog priorities.
*/
std::map<std::string, int> generateConfigTextToPriorityMap() const
throw(castor::exception::Internal);
/**
* Initializes the mutex used to protect the critical section of the
* LoggerImplementation object.
......@@ -316,6 +335,11 @@ private:
// as we do when retrieving logs from the DB
//-------------------------------------------------------------------------
// Ignore messages whose priority is not of interest
if(priority > logMask()) {
return;
}
// Try to find the textual representation of the syslog priority
std::map<int, std::string>::const_iterator priorityTextPair =
m_priorityToText.find(priority);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment