USRP Hardware Driver and Device Manual  Version: 4.11.0.0-0-g0d7ed3b1
UHD and USRP Manual
log_add.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2017 Ettus Research (National Instruments Corp.)
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 // Note: Including this file requires C++11 features enabled.
8 
9 #pragma once
10 
11 #include <uhd/config.hpp>
12 #include <uhd/utils/log.hpp>
14 #include <boost/date_time/posix_time/posix_time_types.hpp>
15 #include <functional>
16 
17 namespace uhd { namespace log {
18 
22 {
23  logging_info() : verbosity(uhd::log::off), line(0) {}
24  logging_info(const boost::posix_time::ptime& time_,
25  const uhd::log::severity_level& verbosity_,
26  const std::string& file_,
27  const unsigned int& line_,
28  const std::string& component_,
29  const std::thread::id& thread_id_)
30  : time(time_)
31  , verbosity(verbosity_)
32  , file(file_)
33  , line(line_)
34  , component(component_)
35  , thread_id(thread_id_)
36  { /* nop */
37  }
38 
39  boost::posix_time::ptime time;
41  std::string file;
42  unsigned int line;
43  std::string component;
44  std::thread::id thread_id;
45  std::string message;
46 };
47 
53 using log_fn_legacy_t = std::function<void(const uhd::log::logging_info&)>;
54 
60 [[deprecated("This function is deprecated. Please use add_logger with log_fn_t "
61  "instead.")]] inline void
62 add_logger(const std::string& key, log_fn_legacy_t logger_fn)
63 {
65  // Convert std::chrono time_point to boost::posix_time::ptime
66  auto time_t_val = std::chrono::system_clock::to_time_t(info.time);
67  auto us = std::chrono::duration_cast<std::chrono::microseconds>(
68  info.time.time_since_epoch())
69  % 1000000;
70  boost::posix_time::ptime ptime =
71  boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1))
72  + boost::posix_time::seconds(time_t_val)
73  + boost::posix_time::microseconds(us.count());
74  uhd::log::logging_info legacy_info(
75  ptime, info.verbosity, info.file, info.line, info.component, info.thread_id);
76  legacy_info.message = info.message;
77  logger_fn(legacy_info);
78  });
79 }
80 
81 
82 }} /* namespace uhd::log */
std::function< void(const uhd::log::logging_info &)> log_fn_legacy_t
Definition: log_add.hpp:53
void add_logger(const std::string &key, log_fn_legacy_t logger_fn)
Definition: log_add.hpp:62
severity_level
Definition: log.hpp:119
@ off
Definition: log.hpp:126
@ info
Definition: log.hpp:122
Definition: build_info.hpp:12
Definition: log.hpp:145
Definition: log_add.hpp:22
std::string file
Definition: log_add.hpp:41
std::thread::id thread_id
Definition: log_add.hpp:44
logging_info(const boost::posix_time::ptime &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_add.hpp:24
logging_info()
Definition: log_add.hpp:23
std::string component
Definition: log_add.hpp:43
boost::posix_time::ptime time
Definition: log_add.hpp:39
unsigned int line
Definition: log_add.hpp:42
uhd::log::severity_level verbosity
Definition: log_add.hpp:40
std::string message
Definition: log_add.hpp:45