Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
5cd91c64
Commit
5cd91c64
authored
8 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Added cta::log::toLogLevel()
parent
af8ee586
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
common/CMakeLists.txt
+2
-0
2 additions, 0 deletions
common/CMakeLists.txt
common/log/LogLevel.cpp
+46
-0
46 additions, 0 deletions
common/log/LogLevel.cpp
common/log/LogLevel.hpp
+34
-0
34 additions, 0 deletions
common/log/LogLevel.hpp
common/log/LogLevelTest.cpp
+91
-0
91 additions, 0 deletions
common/log/LogLevelTest.cpp
with
173 additions
and
0 deletions
common/CMakeLists.txt
+
2
−
0
View file @
5cd91c64
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
common/log/LogLevel.cpp
0 → 100644
+
46
−
0
View file @
5cd91c64
/*
* 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
This diff is collapsed.
Click to expand it.
common/log/LogLevel.hpp
0 → 100644
+
34
−
0
View file @
5cd91c64
/*
* 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
This diff is collapsed.
Click to expand it.
common/log/LogLevelTest.cpp
0 → 100644
+
91
−
0
View file @
5cd91c64
/*
* 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment