forked from UniversalRobots/Universal_Robots_Client_Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.h
92 lines (83 loc) · 2.67 KB
/
log.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright 2017, 2018 Simon Rasmussen (refactor)
*
* Copyright 2015, 2016 Thomas Timm Andersen (original version)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <inttypes.h>
#include <memory>
#define URCL_LOG_DEBUG(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::DEBUG, __VA_ARGS__)
#define URCL_LOG_WARN(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::WARN, __VA_ARGS__)
#define URCL_LOG_INFO(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::INFO, __VA_ARGS__)
#define URCL_LOG_ERROR(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::ERROR, __VA_ARGS__)
#define URCL_LOG_FATAL(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::FATAL, __VA_ARGS__)
namespace urcl
{
/*!
* \brief Different log levels
*/
enum class LogLevel
{
DEBUG = 0,
INFO,
WARN,
ERROR,
FATAL,
NONE
};
/*!
* \brief Inherit from this class to change the behavior when logging messages.
*/
class LogHandler
{
public:
virtual ~LogHandler() = default;
/*!
* \brief Function to log a message
*
* \param file The log message comes from this file
* \param line The log message comes from this line
* \param loglevel Indicates the severity of the log message
* \param log Log message
*/
virtual void log(const char* file, int line, LogLevel loglevel, const char* log) = 0;
};
/*!
* \brief Register a new LogHandler object, for handling log messages.
*
* \param loghandler Pointer to the new object
*/
void registerLogHandler(std::unique_ptr<LogHandler> loghandler);
/*!
* \brief Unregister current log handler, this will enable default log handler.
*/
void unregisterLogHandler();
/*!
* \brief Set log level this will disable messages with lower log level.
*
* \param level desired log level
*/
void setLogLevel(LogLevel level);
/*!
* \brief Log a message, this is used internally by the macros to unpack the log message.
* Use the macros instead of this function directly.
*
* \param file The log message comes from this file
* \param line The log message comes from this line
* \param level Severity of the log message
* \param fmt Format string
*/
void log(const char* file, int line, LogLevel level, const char* fmt, ...);
} // namespace urcl