src
ROSLogHandler.cpp
Go to the documentation of this file.
1
//
3
// © Copyright 2022 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
4
// © Copyright 2022 FZI Forschungszentrum Informatik, Karlsruhe, Germany
5
//
6
// This file is part of the Schunk SVH Driver.
7
//
8
// The Schunk SVH Driver is free software: you can redistribute it and/or
9
// modify it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation, either version 3 of the License, or (at your
11
// option) any later version.
12
//
13
// The Schunk SVH Driver is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16
// Public License for more details.
17
//
18
// You should have received a copy of the GNU General Public License along with
19
// the Schunk SVH Driver. If not, see <https://www.gnu.org/licenses/>.
20
//
22
23
//----------------------------------------------------------------------
30
//----------------------------------------------------------------------
31
32
#include <memory>
33
#include <regex>
34
35
36
#include <
schunk_svh_library/LogLevel.h
>
37
#include <
schunk_svh_library/Logger.h
>
38
39
#include "
ROSLogHandler.h
"
40
41
namespace
driver_svh
{
42
std::unique_ptr<ROSLogHandler>
g_log_handler
(
new
ROSLogHandler);
43
44
void
ROSLogHandler::log
(
const
std::string& file,
45
const
int
line,
46
const
std::string& name,
47
LogLevel
level,
48
const
std::string& msg)
49
{
50
ROSCONSOLE_DEFINE_LOCATION
(
true
,
levelSVH2ROS
(level), std::string(
ROSCONSOLE_NAME_PREFIX
) + name);
51
if
(
ROS_UNLIKELY
(__rosconsole_define_location__enabled))
52
{
53
ros::console::print
(NULL,
54
__rosconsole_define_location__loc.logger_,
55
levelSVH2ROS
(level),
56
file.c_str(),
57
line,
58
""
,
59
"%s"
,
60
msg.c_str());
61
}
62
}
63
64
::ros::console::Level
ROSLogHandler::levelSVH2ROS
(
const
LogLevel
level)
65
{
66
switch
(level)
67
{
68
case
LogLevel::DEBUG
:
69
return ::ros::console::levels::Debug;
70
case
LogLevel::INFO
:
71
return ::ros::console::levels::Info;
72
case
LogLevel::WARN
:
73
return ::ros::console::levels::Warn;
74
case
LogLevel::ERROR
:
75
return ::ros::console::levels::Error;
76
case
LogLevel::FATAL
:
77
return ::ros::console::levels::Fatal;
78
default
:
79
throw
std::invalid_argument(
"Illegal logging level"
);
80
}
81
}
82
83
void
setupROSLogHandler
(
LogLevel
level)
84
{
85
if
(
g_log_handler
!=
nullptr
)
86
{
87
Logger::setLogLevel
(level);
88
Logger::setLogHandler
(std::move(
g_log_handler
));
89
}
90
}
91
}
// namespace driver_svh
driver_svh::ROSLogHandler::log
virtual void log(const std::string &file, const int line, const std::string &name, LogLevel level, const std::string &msg) override
Definition:
ROSLogHandler.cpp:44
ROS_UNLIKELY
#define ROS_UNLIKELY(x)
ROSCONSOLE_NAME_PREFIX
#define ROSCONSOLE_NAME_PREFIX
Logger.h
driver_svh
driver_svh::ROSLogHandler::levelSVH2ROS
::ros::console::Level levelSVH2ROS(const LogLevel level)
Definition:
ROSLogHandler.cpp:64
driver_svh::Logger::setLogHandler
static void setLogHandler(std::unique_ptr< LogHandler > log_handler)
ROSCONSOLE_DEFINE_LOCATION
#define ROSCONSOLE_DEFINE_LOCATION(cond, level, name)
driver_svh::g_log_handler
std::unique_ptr< ROSLogHandler > g_log_handler(new ROSLogHandler)
driver_svh::LogLevel::WARN
@ WARN
ROSLogHandler.h
driver_svh::Logger::setLogLevel
static void setLogLevel(const LogLevel &log_level)
driver_svh::LogLevel::INFO
@ INFO
LogLevel.h
ros::console::levels::Level
Level
driver_svh::LogLevel::DEBUG
@ DEBUG
driver_svh::setupROSLogHandler
void setupROSLogHandler(LogLevel level=LogLevel::INFO)
Definition:
ROSLogHandler.cpp:83
driver_svh::LogLevel
LogLevel
ros::console::print
ROSCONSOLE_DECL void print(FilterBase *filter, void *logger, Level level, const char *file, int line, const char *function, const char *fmt,...) ROSCONSOLE_PRINTF_ATTRIBUTE(7
driver_svh::LogLevel::ERROR
@ ERROR
driver_svh::LogLevel::FATAL
@ FATAL
schunk_svh_driver
Author(s): Georg Heppner
, Felix Exner
, Pascal Becker
, Johannes Mangler
autogenerated on Sat Apr 15 2023 02:24:55