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 #define URCL_LOG_DEBUG(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::DEBUG, __VA_ARGS__)
24 #define URCL_LOG_WARN(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::WARN, __VA_ARGS__)
25 #define URCL_LOG_INFO(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::INFO, __VA_ARGS__)
26 #define URCL_LOG_ERROR(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::ERROR, __VA_ARGS__)
27 #define URCL_LOG_FATAL(...) urcl::log(__FILE__, __LINE__, urcl::LogLevel::FATAL, __VA_ARGS__)
28 
29 namespace urcl
30 {
34 enum class LogLevel
35 {
36  DEBUG = 0,
37  INFO,
38  WARN,
39  ERROR,
40  FATAL,
41  NONE
42 };
43 
48 {
49 public:
50  virtual ~LogHandler() = default;
59  virtual void log(const char* file, int line, LogLevel loglevel, const char* log) = 0;
60 };
61 
67 void registerLogHandler(std::unique_ptr<LogHandler> loghandler);
68 
73 
79 void setLogLevel(LogLevel level);
80 
90 void log(const char* file, int line, LogLevel level, const char* fmt, ...);
91 
92 } // namespace urcl
urcl::LogLevel::DEBUG
@ DEBUG
urcl::setLogLevel
void setLogLevel(LogLevel level)
Set log level this will disable messages with lower log level.
Definition: log.cpp:101
urcl
Definition: bin_parser.h:36
urcl::LogLevel::NONE
@ NONE
urcl::registerLogHandler
void registerLogHandler(std::unique_ptr< LogHandler > loghandler)
Register a new LogHandler object, for handling log messages.
Definition: log.cpp:91
urcl::LogLevel::ERROR
@ ERROR
urcl::unregisterLogHandler
void unregisterLogHandler()
Unregister current log handler, this will enable default log handler.
Definition: log.cpp:96
urcl::LogLevel::WARN
@ WARN
urcl::LogLevel::FATAL
@ FATAL
urcl::LogHandler::~LogHandler
virtual ~LogHandler()=default
urcl::LogHandler
Inherit from this class to change the behavior when logging messages.
Definition: log.h:47
urcl::LogLevel::INFO
@ INFO
urcl::log
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:106
urcl::LogLevel
LogLevel
Different log levels.
Definition: log.h:34
urcl::LogHandler::log
virtual void log(const char *file, int line, LogLevel loglevel, const char *log)=0
Function to log a message.


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Mon May 26 2025 02:35:58