From fa0313652cc25e17e6c3151f67111fb88c62778e Mon Sep 17 00:00:00 2001 From: michael-west Date: Fri, 19 Sep 2014 18:22:13 -0700 Subject: uhd: Fixed logging bug (#476) -- UHD logging has unexplained effect on packet loss. - Removed logging from radio_ctrl_core_3000 - Changed logging facility to prevent type conversion when message is not logged --- host/include/uhd/utils/log.hpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp index 1f515c15e..5baa00108 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -21,8 +21,10 @@ #include #include #include +#include #include #include +#include /*! \file log.hpp * The UHD logging facility. @@ -55,7 +57,7 @@ * Usage: UHD_LOGV(very_rarely) << "the log message" << std::endl; */ #define UHD_LOGV(verbosity) \ - uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)() + uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) /*! * A UHD logger macro with default verbosity. @@ -78,7 +80,7 @@ namespace uhd{ namespace _log{ }; //! Internal logging object (called by UHD_LOG macros) - class UHD_API log{ + class UHD_API log { public: log( const verbosity_t verbosity, @@ -86,10 +88,29 @@ namespace uhd{ namespace _log{ const unsigned int line, const std::string &function ); + ~log(void); - std::ostream &operator()(void); + + // Macro for overloading insertion operators to avoid costly + // conversion of types if not logging. + #define INSERTION_OVERLOAD(x) log& operator<< (x) \ + { \ + if(_log_it) _ss << val; \ + return *this; \ + } + + // General insertion overload + template + INSERTION_OVERLOAD(T val); + + // Insertion overloads for std::ostream manipulators + INSERTION_OVERLOAD(std::ostream& (*val)(std::ostream&)); + INSERTION_OVERLOAD(std::ios& (*val)(std::ios&)); + INSERTION_OVERLOAD(std::ios_base& (*val)(std::ios_base&)); + private: - UHD_PIMPL_DECL(impl) _impl; + std::ostringstream _ss; + bool _log_it; }; }} //namespace uhd::_log -- cgit v1.2.3