11 #include <type_traits>
12 #include <boost/none.hpp>
13 #include <boost/optional.hpp>
113 namespace uhd {
namespace log {
137 const std::string& log_level_str);
149 const std::string& file_,
150 const unsigned int& line_,
151 const std::string& component_,
152 const std::thread::id& thread_id_)
154 , verbosity(verbosity_)
157 , component(component_)
158 , thread_id(thread_id_)
162 std::chrono::system_clock::time_point
time;
173 template <
typename T = boost::optional<uhd::log::severity_level>,
176 boost::optional<uhd::log::
177 severity_level>> || std::is_same_v<T, std::optional<uhd::log::severity_level>>,
181 if constexpr (std::is_same_v<T, boost::optional<uhd::log::severity_level>>) {
183 return bool(level) ? boost::make_optional(*level) : boost::none;
221 #define _UHD_LOG_INTERNAL(component, level) \
222 uhd::_log::log(level, __FILE__, __LINE__, component, std::this_thread::get_id())
226 #if UHD_LOG_MIN_LEVEL < 1
227 # define UHD_LOG_TRACE(component, message) \
228 _UHD_LOG_INTERNAL(component, uhd::log::trace) << message;
230 # define UHD_LOG_TRACE(component, message)
233 #if UHD_LOG_MIN_LEVEL < 2
234 # define UHD_LOG_DEBUG(component, message) \
235 _UHD_LOG_INTERNAL(component, uhd::log::debug) << message;
237 # define UHD_LOG_DEBUG(component, message)
240 #if UHD_LOG_MIN_LEVEL < 3
241 # define UHD_LOG_INFO(component, message) \
242 _UHD_LOG_INTERNAL(component, uhd::log::info) << message;
244 # define UHD_LOG_INFO(component, message)
247 #if UHD_LOG_MIN_LEVEL < 4
248 # define UHD_LOG_WARNING(component, message) \
249 _UHD_LOG_INTERNAL(component, uhd::log::warning) << message;
251 # define UHD_LOG_WARNING(component, message)
254 #if UHD_LOG_MIN_LEVEL < 5
255 # define UHD_LOG_ERROR(component, message) \
256 _UHD_LOG_INTERNAL(component, uhd::log::error) << message;
258 # define UHD_LOG_ERROR(component, message)
261 #define UHD_LOG_THROW(exception_type, component, message) \
263 std::ostringstream __ss; \
265 UHD_LOG_ERROR(component, __ss.str()); \
266 throw exception_type(__ss.str()); \
269 #if UHD_LOG_MIN_LEVEL < 6
270 # define UHD_LOG_FATAL(component, message) \
271 _UHD_LOG_INTERNAL(component, uhd::log::fatal) << message;
273 # define UHD_LOG_FATAL(component, message)
276 #define RFNOC_LOG_TRACE(message) UHD_LOG_TRACE(this->get_unique_id(), message)
277 #define RFNOC_LOG_DEBUG(message) UHD_LOG_DEBUG(this->get_unique_id(), message)
278 #define RFNOC_LOG_INFO(message) UHD_LOG_INFO(this->get_unique_id(), message)
279 #define RFNOC_LOG_WARNING(message) UHD_LOG_WARNING(this->get_unique_id(), message)
280 #define RFNOC_LOG_ERROR(message) UHD_LOG_ERROR(this->get_unique_id(), message)
281 #define RFNOC_LOG_FATAL(message) UHD_LOG_FATAL(this->get_unique_id(), message)
283 #ifndef UHD_LOG_FASTPATH_DISABLE
290 # define UHD_LOG_FASTPATH(message) uhd::_log::log_fastpath(message);
292 # define UHD_LOG_FASTPATH(message)
296 #define UHD_LOGGER_TRACE(component) _UHD_LOG_INTERNAL(component, uhd::log::trace)
297 #define UHD_LOGGER_DEBUG(component) _UHD_LOG_INTERNAL(component, uhd::log::debug)
298 #define UHD_LOGGER_INFO(component) _UHD_LOG_INTERNAL(component, uhd::log::info)
299 #define UHD_LOGGER_WARNING(component) _UHD_LOG_INTERNAL(component, uhd::log::warning)
300 #define UHD_LOGGER_ERROR(component) _UHD_LOG_INTERNAL(component, uhd::log::error)
301 #define UHD_LOGGER_FATAL(component) _UHD_LOG_INTERNAL(component, uhd::log::fatal)
304 #if defined(__GNUG__)
306 # define UHD_HERE() \
307 UHD_LOGGER_DEBUG("DEBUG") \
308 << __FILE__ << ":" << __LINE__ << " (" << UHD_PRETTY_FUNCTION << ")";
311 # define UHD_HERE() UHD_LOGGER_DEBUG("DEBUG") << __FILE__ << ":" << __LINE__;
315 #define UHD_VAR(var) UHD_LOGGER_DEBUG("DEBUG") << #var << " = " << var;
318 #define UHD_HEX(var) \
319 UHD_LOGGER_DEBUG("DEBUG") << #var << " = 0x" << std::hex << std::setfill('0') \
320 << std::setw(8) << var << std::dec;
327 void UHD_API log_fastpath(
const std::string&);
334 const std::string& file,
335 const unsigned int line,
336 const std::string& component,
337 const std::thread::id thread_id);
343 #define INSERTION_OVERLOAD(x) \
353 template <
typename T>
354 INSERTION_OVERLOAD(T val);
357 INSERTION_OVERLOAD(std::ostream& (*val)(std::ostream&));
358 INSERTION_OVERLOAD(std::ios& (*val)(std::ios&));
359 INSERTION_OVERLOAD(std::ios_base& (*val)(std::ios_base&));
363 std::ostringstream _ss;
#define UHD_API
Definition: config.h:87
UHD_API std::optional< uhd::log::severity_level > parse_log_level_from_string_impl(const std::string &log_level_str)
UHD_API void set_logger_level(const std::string &logger, uhd::log::severity_level level)
T parse_log_level_from_string(const std::string &log_level_str)
Definition: log.hpp:179
UHD_API void set_console_level(uhd::log::severity_level level)
UHD_API void set_log_level(uhd::log::severity_level level)
UHD_API void set_file_level(uhd::log::severity_level level)
severity_level
Definition: log.hpp:119
@ warning
Definition: log.hpp:123
@ fatal
Definition: log.hpp:125
@ error
Definition: log.hpp:124
@ trace
Definition: log.hpp:120
@ off
Definition: log.hpp:126
@ info
Definition: log.hpp:122
@ debug
Definition: log.hpp:121
Definition: build_info.hpp:12
std::string message
Definition: log.hpp:168
uhd::log::severity_level verbosity
Definition: log.hpp:163
unsigned int line
Definition: log.hpp:165
std::chrono::system_clock::time_point time
Definition: log.hpp:162
std::string file
Definition: log.hpp:164
std::string component
Definition: log.hpp:166
std::thread::id thread_id
Definition: log.hpp:167
logging_info()
Definition: log.hpp:146
logging_info(const std::chrono::system_clock::time_point &time_, const uhd::log::severity_level &verbosity_, const std::string &file_, const unsigned int &line_, const std::string &component_, const std::thread::id &thread_id_)
Definition: log.hpp:147