Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
90243332
Commit
90243332
authored
Nov 09, 2016
by
Steven Murray
Browse files
Added cta::log::toLogLevel()
parent
7c2b1fcf
Changes
4
Hide whitespace changes
Inline
Side-by-side
common/CMakeLists.txt
View file @
90243332
...
...
@@ -90,6 +90,7 @@ set (COMMON_LIB_SRC_FILES
log/DummyLogger.cpp
log/LogContext.cpp
log/Logger.cpp
log/LogLevel.cpp
log/Message.cpp
log/Param.cpp
log/StringLogger.cpp
...
...
@@ -143,6 +144,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES
dataStructures/StorageClassTest.cpp
processCap/SmartCapTest.cpp
log/LogContextTest.cpp
log/LogLevelTest.cpp
log/ParamTest.cpp
log/SyslogLoggerTest.cpp
log/StringLoggerTest.cpp
...
...
common/log/LogLevel.cpp
0 → 100644
View file @
90243332
/*
* 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
common/log/LogLevel.hpp
0 → 100644
View file @
90243332
/*
* 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
common/log/LogLevelTest.cpp
0 → 100644
View file @
90243332
/*
* 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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment