diff options
author | Martin Braun <martin.braun@ettus.com> | 2014-09-24 18:20:51 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2014-09-24 18:20:51 -0700 |
commit | 3cfb643100d0b44da5a37d672680d1c5b8990ece (patch) | |
tree | c05673d400d1e42921ec70b08f2e0e74f1466662 /host/include | |
parent | 5aefa0fdfcf45717c133641b7e4df8070ed025e3 (diff) | |
parent | ecdd34c08b79117c4f739b336daeb4b9d2bc8df3 (diff) | |
download | uhd-3cfb643100d0b44da5a37d672680d1c5b8990ece.tar.gz uhd-3cfb643100d0b44da5a37d672680d1c5b8990ece.tar.bz2 uhd-3cfb643100d0b44da5a37d672680d1c5b8990ece.zip |
Merge branch 'maint'
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/utils/log.hpp | 29 |
1 files changed, 25 insertions, 4 deletions
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 <uhd/config.hpp> #include <uhd/utils/pimpl.hpp> #include <boost/current_function.hpp> +#include <boost/format.hpp> #include <ostream> #include <string> +#include <sstream> /*! \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 <typename T> + 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 |