log.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017, 2018 Simon Rasmussen (refactor)
3  *
4  * Copyright 2015, 2016 Thomas Timm Andersen (original version)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 #include <inttypes.h>
21 #include <memory>
22 
23 #ifdef ROS_BUILD
24 #include <console_bridge/console.h>
25 
26 #define URCL_LOG_DEBUG CONSOLE_BRIDGE_logDebug
27 #define URCL_LOG_WARN CONSOLE_BRIDGE_logWarn
28 #define URCL_LOG_INFO CONSOLE_BRIDGE_logInform
29 #define URCL_LOG_ERROR CONSOLE_BRIDGE_logError
30 #define URCL_LOG_FATAL CONSOLE_BRIDGE_logError
31 
32 #else
33 
34 #define URCL_LOG_DEBUG(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::DEBUG, __VA_ARGS__)
35 #define URCL_LOG_WARN(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::WARN, __VA_ARGS__)
36 #define URCL_LOG_INFO(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::INFO, __VA_ARGS__)
37 #define URCL_LOG_ERROR(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::ERROR, __VA_ARGS__)
38 #define URCL_LOG_FATAL(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::FATAL, __VA_ARGS__)
39 
40 #endif
41 
42 namespace urcl
43 {
47 enum class LogLevel
48 {
49  DEBUG = 0,
50  INFO,
51  WARN,
52  ERROR,
53  FATAL,
54  NONE
55 };
56 
61 {
62 public:
63  virtual ~LogHandler() = default;
72  virtual void log(const char* file, int line, LogLevel loglevel, const char* log) = 0;
73 };
74 
80 void registerLogHandler(std::unique_ptr<LogHandler> loghandler);
81 
86 
92 void setLogLevel(LogLevel level);
93 
103 void log(const char* file, int line, LogLevel level, const char* fmt, ...);
104 
105 } // namespace urcl
void log(const char *file, int line, LogLevel level, const char *fmt,...)
Log a message, this is used internally by the macros to unpack the log message. Use the macros instea...
Definition: log.cpp:105
void setLogLevel(LogLevel level)
Set log level this will disable messages with lower log level.
Definition: log.cpp:100
void unregisterLogHandler()
Unregister current log handler, this will enable default log handler.
Definition: log.cpp:95
Inherit from this class to change the behavior when logging messages.
Definition: log.h:60
LogLevel
Different log levels.
Definition: log.h:47
void registerLogHandler(std::unique_ptr< LogHandler > loghandler)
Register a new LogHandler object, for handling log messages.
Definition: log.cpp:90


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Sun May 9 2021 02:16:26