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

Added cta::log::toLogLevel()

parent af8ee586
No related branches found
No related tags found
No related merge requests found
...@@ -90,6 +90,7 @@ set (COMMON_LIB_SRC_FILES ...@@ -90,6 +90,7 @@ set (COMMON_LIB_SRC_FILES
log/DummyLogger.cpp log/DummyLogger.cpp
log/LogContext.cpp log/LogContext.cpp
log/Logger.cpp log/Logger.cpp
log/LogLevel.cpp
log/Message.cpp log/Message.cpp
log/Param.cpp log/Param.cpp
log/StringLogger.cpp log/StringLogger.cpp
...@@ -143,6 +144,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES ...@@ -143,6 +144,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES
dataStructures/StorageClassTest.cpp dataStructures/StorageClassTest.cpp
processCap/SmartCapTest.cpp processCap/SmartCapTest.cpp
log/LogContextTest.cpp log/LogContextTest.cpp
log/LogLevelTest.cpp
log/ParamTest.cpp log/ParamTest.cpp
log/SyslogLoggerTest.cpp log/SyslogLoggerTest.cpp
log/StringLoggerTest.cpp log/StringLoggerTest.cpp
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/Exception.hpp"
#include "common/log/Constants.hpp"
namespace cta {
namespace log {
//------------------------------------------------------------------------------
// toLogLevel
//------------------------------------------------------------------------------
int toLogLevel(const std::string &s) {
if(s == "EMERG") return EMERG;
if(s == "ALERT") return ALERT;
if(s == "CRIT") return CRIT;
if(s == "ERR") return ERR;
if(s == "WARNING") return WARNING;
if(s == "NOTICE") return NOTICE;
if(s == "INFO") return INFO;
if(s == "DEBUG") return DEBUG;
// It is a convention of CTA to use syslog level of LOG_NOTICE to label
// user errors.
if(s == "USERERR") return NOTICE;
throw exception::Exception(s + " is not a valid log level");
}
} // namespace log
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common/log/Constants.hpp"
#include <string>
namespace cta {
namespace log {
/**
* Returns the numeric value of the specified log level.
*/
int toLogLevel(const std::string &s);
} // namespace log
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "common/log/LogLevel.hpp"
#include <gtest/gtest.h>
namespace unitTests {
class cta_log_LogLevelTest : public ::testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
}; // class cta_log_LogLevelTest
TEST_F(cta_log_LogLevelTest, toLogLevel_EMERG) {
using namespace cta::log;
ASSERT_EQ(EMERG, toLogLevel("EMERG"));
}
TEST_F(cta_log_LogLevelTest, toLogLevel_ALERT) {
using namespace cta::log;
ASSERT_EQ(ALERT, toLogLevel("ALERT"));
}
TEST_F(cta_log_LogLevelTest, toLogLevel_CRIT) {
using namespace cta::log;
ASSERT_EQ(CRIT, toLogLevel("CRIT"));
}
TEST_F(cta_log_LogLevelTest, toLogLevel_ERR) {
using namespace cta::log;
ASSERT_EQ(ERR, toLogLevel("ERR"));
}
TEST_F(cta_log_LogLevelTest, toLogLevel_WARNING) {
using namespace cta::log;
ASSERT_EQ(WARNING, toLogLevel("WARNING"));
}
TEST_F(cta_log_LogLevelTest, toLogLevel_NOTICE) {
using namespace cta::log;
ASSERT_EQ(NOTICE, toLogLevel("NOTICE"));
}
TEST_F(cta_log_LogLevelTest, toLogLevel_INFO) {
using namespace cta::log;
ASSERT_EQ(INFO, toLogLevel("INFO"));
}
TEST_F(cta_log_LogLevelTest, toLogLevel_DEBUG) {
using namespace cta::log;
ASSERT_EQ(DEBUG, toLogLevel("DEBUG"));
}
TEST_F(cta_log_LogLevelTest, toLogLevel_USERERR) {
using namespace cta::log;
// It is a convention of CTA to use syslog level of LOG_NOTICE to label
// user errors.
ASSERT_EQ(NOTICE, toLogLevel("USERERR"));
}
} // namespace unitTests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment