Commit c4c4d040 authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

Removed castor::log:: classes

parent bc51df0f
......@@ -91,7 +91,7 @@ cta::common::Configuration &
//------------------------------------------------------------------------------
const std::string& cta::common::Configuration::getConfEntString(
const std::string &category, const std::string &key,
const std::string &defaultValue, log::Logger *const log) {
const std::string &defaultValue, cta::log::Logger *const log) {
try {
if (isStale()) {
tryToRenewConfig();
......@@ -113,11 +113,11 @@ const std::string& cta::common::Configuration::getConfEntString(
// release the lock
pthread_rwlock_unlock(&m_lock);
if(NULL != log) {
std::list<log::Param> params = {
log::Param("category", category),
log::Param("key", key),
log::Param("value", entIt->second),
log::Param("source", m_fileName)};
std::list<cta::log::Param> params = {
cta::log::Param("category", category),
cta::log::Param("key", key),
cta::log::Param("value", entIt->second),
cta::log::Param("source", m_fileName)};
(*log)(log::INFO, "Configuration entry", params);
}
return entIt->second;
......@@ -125,11 +125,11 @@ const std::string& cta::common::Configuration::getConfEntString(
}
// no entry found
if(NULL != log) {
std::list<log::Param> params = {
log::Param("category", category),
log::Param("key", key),
log::Param("value", defaultValue),
log::Param("source", "DEFAULT")};
std::list<cta::log::Param> params = {
cta::log::Param("category", category),
cta::log::Param("key", key),
cta::log::Param("value", defaultValue),
cta::log::Param("source", "DEFAULT")};
(*log)(log::INFO, "Configuration entry", params);
}
// Unlock and return default
......@@ -139,11 +139,11 @@ const std::string& cta::common::Configuration::getConfEntString(
pthread_rwlock_unlock(&m_lock);
// log the exception
if(NULL != log) {
std::list<log::Param> params = {
log::Param("category", category),
log::Param("key", key),
log::Param("value", defaultValue),
log::Param("source", "DEFAULT")};
std::list<cta::log::Param> params = {
cta::log::Param("category", category),
cta::log::Param("key", key),
cta::log::Param("value", defaultValue),
cta::log::Param("source", "DEFAULT")};
(*log)(log::INFO, "Configuration entry", params);
}
} catch (...) {
......@@ -158,7 +158,7 @@ const std::string& cta::common::Configuration::getConfEntString(
// getConfEntString
//------------------------------------------------------------------------------
const std::string& cta::common::Configuration::getConfEntString(
const std::string &category, const std::string &key, log::Logger *const log) {
const std::string &category, const std::string &key, cta::log::Logger *const log) {
// check whether we need to reload the configuration
if (isStale()) {
tryToRenewConfig();
......@@ -191,11 +191,11 @@ const std::string& cta::common::Configuration::getConfEntString(
}
if(NULL != log) {
std::list<log::Param> params = {
log::Param("category", category),
log::Param("key", key),
log::Param("value", entIt->second),
log::Param("source", m_fileName)};
std::list<cta::log::Param> params = {
cta::log::Param("category", category),
cta::log::Param("key", key),
cta::log::Param("value", entIt->second),
cta::log::Param("source", m_fileName)};
(*log)(log::INFO, "Configuration entry", params);
}
......
......@@ -90,7 +90,7 @@ namespace cta { namespace common {
*/
const std::string& getConfEntString(const std::string &category,
const std::string &key, const std::string &defaultValue,
log::Logger *const log = NULL);
cta::log::Logger *const log = NULL);
/**
* Retrieves a configuration entry.
......@@ -107,7 +107,7 @@ namespace cta { namespace common {
* @param log pointer to NULL or an optional logger object
*/
const std::string& getConfEntString(const std::string &category,
const std::string &key, log::Logger *const log = NULL);
const std::string &key, cta::log::Logger *const log = NULL);
/**
* Retrieves a configuration entry as an integer.
......@@ -126,17 +126,17 @@ namespace cta { namespace common {
*/
template<typename T> T getConfEntInt(const std::string &category,
const std::string &key, const T defaultValue,
log::Logger *const log = NULL) {
cta::log::Logger *const log = NULL) {
std::string strValue;
try {
strValue = getConfEntString(category, key);
} catch(cta::exception::Exception &ex) {
if(NULL != log) {
std::list<log::Param> params = {
log::Param("category", category),
log::Param("key", key),
log::Param("value", defaultValue),
log::Param("source", "DEFAULT")};
std::list<cta::log::Param> params = {
cta::log::Param("category", category),
cta::log::Param("key", key),
cta::log::Param("value", defaultValue),
cta::log::Param("source", "DEFAULT")};
(*log)(log::INFO, "Configuration entry", params);
}
return defaultValue;
......@@ -157,11 +157,11 @@ namespace cta { namespace common {
ss >> value;
if(NULL != log) {
std::list<log::Param> params = {
log::Param("category", category),
log::Param("key", key),
log::Param("value", value),
log::Param("source", m_fileName)};
std::list<cta::log::Param> params = {
cta::log::Param("category", category),
cta::log::Param("key", key),
cta::log::Param("value", value),
cta::log::Param("source", m_fileName)};
(*log)(log::INFO, "Configuration entry", params);
}
......@@ -181,7 +181,7 @@ namespace cta { namespace common {
* @return the integer value
*/
template<typename T> T getConfEntInt(const std::string &category,
const std::string &key, log::Logger *const log = NULL) {
const std::string &key, cta::log::Logger *const log = NULL) {
const std::string strValue = getConfEntString(category, key);
if (!utils::isValidUInt(strValue.c_str())) {
......@@ -198,11 +198,11 @@ namespace cta { namespace common {
ss >> value;
if(NULL != log) {
std::list<log::Param> params = {
log::Param("category", category),
log::Param("key", key),
log::Param("value", value),
log::Param("source", m_fileName)};
std::list<cta::log::Param> params = {
cta::log::Param("category", category),
cta::log::Param("key", key),
cta::log::Param("value", value),
cta::log::Param("source", m_fileName)};
(*log)(log::INFO, "Configuration entry", params);
}
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
......
/*******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
******************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/log/DummyLogger.hpp"
namespace cta {
namespace log {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::log::DummyLogger::DummyLogger(const std::string &programName):
DummyLogger::DummyLogger(const std::string &programName):
Logger(programName, DEBUG) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
cta::log::DummyLogger::~DummyLogger() {
DummyLogger::~DummyLogger() {
}
//------------------------------------------------------------------------------
// prepareForFork
//------------------------------------------------------------------------------
void cta::log::DummyLogger::prepareForFork() {}
void DummyLogger::prepareForFork() {}
//------------------------------------------------------------------------------
// reducedSyslog
//------------------------------------------------------------------------------
void cta::log::DummyLogger::reducedSyslog(const std::string & msg) {}
void DummyLogger::reducedSyslog(const std::string & msg) {}
} // namespace log
} // namespace cta
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/log/LogContext.hpp"
#include "common/log/Param.hpp"
......@@ -29,10 +24,13 @@
#include <algorithm>
#include <bfd.h>
cta::log::LogContext::LogContext(Logger& logger) throw():
namespace cta {
namespace log {
LogContext::LogContext(Logger& logger) throw():
m_log(logger) {}
void cta::log::LogContext::pushOrReplace(const Param& param) throw() {
void LogContext::pushOrReplace(const Param& param) throw() {
ParamNameMatcher match(param.getName());
std::list<Param>::iterator i =
std::find_if(m_params.begin(), m_params.end(), match);
......@@ -43,16 +41,16 @@ void cta::log::LogContext::pushOrReplace(const Param& param) throw() {
}
}
void cta::log::LogContext::erase(const std::string& paramName) throw() {
void LogContext::erase(const std::string& paramName) throw() {
ParamNameMatcher match(paramName);
m_params.erase(std::remove_if(m_params.begin(), m_params.end(), match), m_params.end());
}
void cta::log::LogContext::log(const int priority, const std::string& msg) throw() {
void LogContext::log(const int priority, const std::string& msg) throw() {
m_log(priority, msg, m_params);
}
void cta::log::LogContext::logBacktrace(const int priority,
void LogContext::logBacktrace(const int priority,
const std::string& backtrace) throw() {
// Sanity check to prevent substr from throwing exceptions
if (!backtrace.size())
......@@ -75,26 +73,26 @@ void cta::log::LogContext::logBacktrace(const int priority,
line = backtrace.substr(position);
}
if (line.size()) {
ScopedParam sp1 (*this, cta::log::Param("traceFrameNumber", lineNumber++));
ScopedParam sp2 (*this, cta::log::Param("traceFrame", line));
ScopedParam sp1 (*this, Param("traceFrameNumber", lineNumber++));
ScopedParam sp2 (*this, Param("traceFrame", line));
log(priority, "Stack trace");
}
}
}
cta::log::LogContext::ScopedParam::ScopedParam(
LogContext::ScopedParam::ScopedParam(
LogContext& context,
const Param& param) throw():
m_context(context), m_name(param.getName()) {
m_context.pushOrReplace(param);
}
cta::log::LogContext::ScopedParam::~ScopedParam() throw() {
LogContext::ScopedParam::~ScopedParam() throw() {
m_context.erase(m_name);
}
std::ostream & cta::log::operator << (std::ostream & os,
const cta::log::LogContext & lc) {
std::ostream & operator << (std::ostream & os,
const LogContext & lc) {
bool first=true;
for (std::list<Param>::const_iterator p = lc.m_params.begin();
p != lc.m_params.end(); ++p) {
......@@ -107,3 +105,6 @@ std::ostream & cta::log::operator << (std::ostream & os,
}
return os;
}
} // namespace log
} // namespace cta
\ No newline at end of file
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
......@@ -44,7 +39,7 @@ public:
* @param programName The name of the program to be prepended to every log
* message.
*/
LogContext(cta::log::Logger &logger)
LogContext(Logger&logger)
throw();
/**
......@@ -56,7 +51,7 @@ public:
* Access to the logger object.
* @return reference to this context's logger
*/
cta::log::Logger & logger() throw() { return m_log; }
Logger & logger() throw() { return m_log; }
/**
* Add a parameter to the container. Replaces any parameter going by the same
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/log/DummyLogger.hpp"
#include "common/log/LogContext.hpp"
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/log/Logger.hpp"
#include "common/utils/utils.hpp"
......@@ -28,10 +23,13 @@
#include <sys/syslog.h>
#include <sys/syscall.h>
namespace cta {
namespace log {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::log::Logger::Logger(const std::string &programName, const int logMask):
Logger::Logger(const std::string &programName, const int logMask):
m_programName(programName), m_logMask(logMask),
m_maxMsgLen(determineMaxMsgLen()),
m_priorityToText(generatePriorityToTextMap()) {}
......@@ -39,20 +37,20 @@ cta::log::Logger::Logger(const std::string &programName, const int logMask):
//------------------------------------------------------------------------------
// getProgramName
//------------------------------------------------------------------------------
const std::string &cta::log::Logger::getProgramName() const {
const std::string &Logger::getProgramName() const {
return m_programName;
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
cta::log::Logger::~Logger() {
Logger::~Logger() {
}
//-----------------------------------------------------------------------------
// operator()
//-----------------------------------------------------------------------------
void cta::log::Logger::operator() (
void Logger::operator() (
const int priority,
const std::string &msg,
const std::list<Param> &params) {
......@@ -107,7 +105,7 @@ void cta::log::Logger::operator() (
//-----------------------------------------------------------------------------
// writeLogMsg
//-----------------------------------------------------------------------------
void cta::log::Logger::writeLogMsg(
void Logger::writeLogMsg(
std::ostringstream &os,
const int priority,
const std::string &priorityText,
......@@ -162,7 +160,7 @@ void cta::log::Logger::writeLogMsg(
//-----------------------------------------------------------------------------
// writeHeader
//-----------------------------------------------------------------------------
void cta::log::Logger::writeHeader(
void Logger::writeHeader(
std::ostringstream &os,
const int priority,
const struct timeval &timeStamp,
......@@ -191,7 +189,7 @@ void cta::log::Logger::writeHeader(
//-----------------------------------------------------------------------------
// cleanString
//-----------------------------------------------------------------------------
std::string cta::log::Logger::cleanString(const std::string &s,
std::string Logger::cleanString(const std::string &s,
const bool replaceUnderscores) {
// Trim both left and right white-space
std::string result = utils::trimString(s);
......@@ -220,7 +218,7 @@ std::string cta::log::Logger::cleanString(const std::string &s,
//------------------------------------------------------------------------------
// determineMaxMsgLen
//------------------------------------------------------------------------------
size_t cta::log::Logger::determineMaxMsgLen() {
size_t Logger::determineMaxMsgLen() {
size_t msgSize = 0;