Commit cfab8e54 authored by Steven Murray's avatar Steven Murray
Browse files

Added name of host to log message header.

parent 2326c9f5
......@@ -29,7 +29,7 @@ namespace unitTests {
class cta_catalogue_CatalogueFactoryTest : public ::testing::Test {
public:
cta_catalogue_CatalogueFactoryTest():
m_dummyLog("dummy") {
m_dummyLog("dummy", "dummy") {
m_localAdmin.username = "local_admin_user";
m_localAdmin.host = "local_admin_host";
......
......@@ -40,7 +40,7 @@ namespace unitTests {
// constructor
//------------------------------------------------------------------------------
cta_catalogue_CatalogueTest::cta_catalogue_CatalogueTest():
m_dummyLog("dummy") {
m_dummyLog("dummy", "dummy") {
m_localAdmin.username = "local_admin_user";
m_localAdmin.host = "local_admin_host";
......
......@@ -57,7 +57,7 @@ int CreateAdminHostCmd::exceptionThrowingMain(const int argc, char *const *const
const rdbms::Login dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath);
const uint64_t nbDbConns = 1;
const uint64_t nbArchiveFileListingDbConns = 0;
log::DummyLogger dummyLog("dummy");
log::DummyLogger dummyLog("dummy", "dummy");
auto catalogue = CatalogueFactory::create(dummyLog, dbLogin, nbDbConns, nbArchiveFileListingDbConns);
const common::dataStructures::SecurityIdentity adminRunningCommand(getUsername(), getHostname());
......
......@@ -56,7 +56,7 @@ int CreateAdminUserCmd::exceptionThrowingMain(const int argc, char *const *const
const rdbms::Login dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath);
const uint64_t nbDbConns = 1;
const uint64_t nbArchiveFileListingDbConns = 1;
log::DummyLogger dummyLog("dummy");
log::DummyLogger dummyLog("dummy", "dummy");
auto catalogue = CatalogueFactory::create(dummyLog, dbLogin, nbDbConns, nbArchiveFileListingDbConns);
const common::dataStructures::SecurityIdentity adminRunningCommand(getUsername(), getHostname());
......
......@@ -36,7 +36,7 @@ protected:
TEST_F(cta_catalogue_InMemoryCatalogue, createSameSchemaInTwoSeparateInMemoryDatabases) {
using namespace cta;
log::DummyLogger dummyLog("dummy");
log::DummyLogger dummyLog("dummy", "dummy");
const uint64_t nbConns = 1;
const uint64_t nbArchiveFileListingConns = 0;
const uint32_t maxTriesToConnect = 1;
......
......@@ -24,8 +24,8 @@ namespace log {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
DummyLogger::DummyLogger(const std::string &programName):
Logger(programName, DEBUG) {
DummyLogger::DummyLogger(const std::string &hostName, const std::string &programName):
Logger(hostName, programName, DEBUG) {
}
//------------------------------------------------------------------------------
......
......@@ -38,10 +38,11 @@ public:
/**
* Constructor
*
* @param hostName The name of the host to be prepended to every log
* @param programName The name of the program to be prepended to every log
* message.
*/
DummyLogger(const std::string &programName);
DummyLogger(const std::string &hostName, const std::string &programName);
/**
* Destructor.
......
......@@ -30,9 +30,9 @@ namespace log {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
FileLogger::FileLogger(const std::string &programName, const std::string &filePath,
FileLogger::FileLogger(const std::string &hostName, const std::string &programName, const std::string &filePath,
const int logMask):
Logger(programName, logMask) {
Logger(hostName, programName, logMask) {
m_fd = ::open(filePath.c_str(), O_APPEND | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP);
cta::exception::Errnum::throwOnMinusOne(m_fd,
std::string("In FileLogger::FileLogger(): failed to open log file: ") + filePath);
......
......@@ -33,12 +33,13 @@ public:
/**
* Constructor
*
* @param hostName The host name to be prepended to every log message.
* @param programName The name of the program to be prepended to every log
* message.
* @param filePath path to the log file.
* @param logMask The log mask.
*/
FileLogger(const std::string &programName, const std::string &filePath,
FileLogger(const std::string &hostName, const std::string &programName, const std::string &filePath,
const int logMask);
/**
......
......@@ -29,7 +29,7 @@ namespace unitTests {
TEST(cta_log_FileLogger, basicTest) {
std::string jat = "Just a test";
TempFile tf;
FileLogger fl("cta_log_StringLogger", tf.path(), DEBUG);
FileLogger fl("dummy", "cta_log_StringLogger", tf.path(), DEBUG);
fl(INFO, jat);
std::ifstream ifs(tf.path());
std::stringstream res;
......
......@@ -26,7 +26,7 @@ using namespace cta::log;
namespace unitTests {
TEST(cta_log_LogContextTest, additionScopedRemove) {
DummyLogger dl("cta_log_LogContextTest");
DummyLogger dl("dummy", "cta_log_LogContextTest");
LogContext lc(dl);
lc.pushOrReplace(Param("MigrationRequestId", 123));
ASSERT_EQ(1U, lc.size());
......@@ -50,7 +50,7 @@ namespace unitTests {
}
TEST(cta_log_LogContextTest, paramsFound) {
StringLogger sl ("cta_log_LogContextTest", DEBUG);
StringLogger sl ("dummy", "cta_log_LogContextTest", DEBUG);
LogContext lc(sl);
lc.pushOrReplace(Param("MigrationRequestId", 123));
lc.log(INFO, "First log");
......
......@@ -30,8 +30,8 @@ namespace log {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
Logger::Logger(const std::string &programName, const int logMask):
m_programName(programName), m_logMask(logMask),
Logger::Logger(const std::string &hostName, const std::string &programName, const int logMask):
m_hostName(hostName), m_programName(programName), m_logMask(logMask),
m_priorityToText(generatePriorityToTextMap()) {}
//------------------------------------------------------------------------------
......@@ -77,7 +77,7 @@ void Logger::operator() (
// Safe to get a reference to the textual representation of the priority
const std::string &priorityText = priorityTextPair->second;
const std::string header = createMsgHeader(timeStamp, m_programName, pid);
const std::string header = createMsgHeader(timeStamp, m_hostName, m_programName, pid);
const std::string body = createMsgBody(priority, priorityText, msg, params, rawParams, m_programName, pid);
writeMsgToUnderlyingLoggingSystem(header, body);
......@@ -188,6 +188,7 @@ void Logger::setLogMask(const int logMask) {
//-----------------------------------------------------------------------------
std::string Logger::createMsgHeader(
const struct timeval &timeStamp,
const std::string &hostName,
const std::string &programName,
const int pid) {
std::ostringstream os;
......@@ -201,7 +202,7 @@ std::string Logger::createMsgHeader(
len += snprintf(buf + len, bufLen - len, ".%06ld ",
(unsigned long)timeStamp.tv_usec);
buf[sizeof(buf) - 1] = '\0';
os << buf << programName << ": ";
os << buf << hostName << " " << programName << ": ";
return os.str();
}
......
......@@ -89,11 +89,12 @@ public:
/**
* Constructor
*
* @param hostName The name of the host to be prepended to every log
* @param programName The name of the program to be prepended to every log
* @param logMask The log mask.
* message.
*/
Logger(const std::string &programName, const int logMask);
Logger(const std::string &hostName, const std::string &programName, const int logMask);
/**
* Destructor.
......@@ -157,6 +158,11 @@ public:
protected:
/**
* The name of the host to be prepended to every log message.
*/
const std::string m_hostName;
/**
* The name of the program to be prepended to every log message.
*/
......@@ -218,12 +224,14 @@ private:
* this method.
*
* @param timeStamp The time stamp of the message.
* @param hostName The name of the host.
* @param programName the program name of the log message.
* @param pid The process ID of the process logging the message.
* @return The message header.
*/
static std::string createMsgHeader(
const struct timeval &timeStamp,
const std::string &hostName,
const std::string &programName,
const int pid);
......
......@@ -24,8 +24,8 @@ namespace log {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
StdoutLogger::StdoutLogger(const std::string &programName):
Logger(programName, DEBUG) {
StdoutLogger::StdoutLogger(const std::string &hostName, const std::string &programName):
Logger(hostName, programName, DEBUG) {
}
//------------------------------------------------------------------------------
......
......@@ -32,10 +32,11 @@ public:
/**
* Constructor
*
* @param hostName The name of the host to be prepended to every log message.
* @param programName The name of the program to be prepended to every log
* message.
*/
StdoutLogger(const std::string &programName);
StdoutLogger(const std::string &hostName, const std::string &programName);
/**
* Destructor.
......
......@@ -26,9 +26,9 @@ namespace log {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
StringLogger::StringLogger(const std::string &programName,
StringLogger::StringLogger(const std::string &hostName, const std::string &programName,
const int logMask):
Logger(programName, logMask) {}
Logger(hostName, programName, logMask) {}
//------------------------------------------------------------------------------
// destructor
......
......@@ -33,11 +33,12 @@ public:
/**
* Constructor
*
* @param hostName The name of the host to be prepended to every log mesage.
* @param programName The name of the program to be prepended to every log
* message.
* @param logMask The log mask.
*/
StringLogger(const std::string &programName, const int logMask);
StringLogger(const std::string &hostName, const std::string &programName, const int logMask);
/**
* Destructor.
......
......@@ -25,7 +25,7 @@ using namespace cta::log;
namespace unitTests {
TEST(cta_log_StringLogger, basicTest) {
std::string jat = "Just a test";
StringLogger sl("cta_log_StringLogger", DEBUG);
StringLogger sl("dummy", "cta_log_StringLogger", DEBUG);
sl(INFO, jat);
ASSERT_NE(std::string::npos, sl.getLog().find(jat));
}
......
......@@ -43,8 +43,8 @@ namespace log {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
SyslogLogger::SyslogLogger(const std::string &programName, const int logMask):
Logger(programName, logMask) {
SyslogLogger::SyslogLogger(const std::string &hostName, const std::string &programName, const int logMask):
Logger(hostName, programName, logMask) {
const int option = 0;
const int facility = 0;
openlog(m_programName.c_str(), option, facility);
......
......@@ -40,11 +40,12 @@ public:
/**
* Constructor
*
* @param hostName The name of the host to be prepended to every log message.
* @param programName The name of the program to be prepended to every log
* message.
* @param logMask The log mask.
*/
SyslogLogger(const std::string &programName, const int logMask);
SyslogLogger(const std::string &hostName, const std::string &programName, const int logMask);
/**
* Destructor.
......
Markdown is supported
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