USRP Hardware Driver and USRP Manual  Version: 003.010.003.HEAD-0-gef157678
UHD and USRP Manual
log.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2011 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_UHD_UTILS_LOG_HPP
19 #define INCLUDED_UHD_UTILS_LOG_HPP
20 
21 #include <uhd/config.hpp>
22 #include <uhd/utils/pimpl.hpp>
23 #include <boost/current_function.hpp>
24 #include <boost/format.hpp>
25 #include <ostream>
26 #include <string>
27 #include <sstream>
28 
59 #define UHD_LOGV(verbosity) \
60  uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
61 
66 #define UHD_LOG \
67  UHD_LOGV(regularly)
68 
69 
70 namespace uhd{ namespace _log{
71 
74  always = 1,
75  often = 2,
76  regularly = 3,
77  rarely = 4,
79  never = 6
80  };
81 
83  class UHD_API log {
84  public:
85  log(
86  const verbosity_t verbosity,
87  const std::string &file,
88  const unsigned int line,
89  const std::string &function
90  );
91 
92  ~log(void);
93 
94  // Macro for overloading insertion operators to avoid costly
95  // conversion of types if not logging.
96  #define INSERTION_OVERLOAD(x) log& operator<< (x) \
97  { \
98  if(_log_it) _ss << val; \
99  return *this; \
100  }
101 
102  // General insertion overload
103  template <typename T>
105 
106  // Insertion overloads for std::ostream manipulators
107  INSERTION_OVERLOAD(std::ostream& (*val)(std::ostream&))
108  INSERTION_OVERLOAD(std::ios& (*val)(std::ios&))
109  INSERTION_OVERLOAD(std::ios_base& (*val)(std::ios_base&))
110 
111  private:
112  std::ostringstream _ss;
113  bool _log_it;
114  };
115 
116 }} //namespace uhd::_log
117 
118 #endif /* INCLUDED_UHD_UTILS_LOG_HPP */
Definition: log.hpp:74
#define INSERTION_OVERLOAD(x)
Definition: log.hpp:96
Definition: log.hpp:76
Definition: log.hpp:79
STL namespace.
Definition: build_info.hpp:25
Internal logging object (called by UHD_LOG macros)
Definition: log.hpp:83
verbosity_t
Verbosity levels for the logger.
Definition: log.hpp:73
Definition: log.hpp:77
#define UHD_API
Definition: config.h:73
Definition: log.hpp:75
Definition: log.hpp:78