From 94399062713a76a42f269a7ed4d3737ecd6ed5cf Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 14:33:35 -0700 Subject: uhd: tweaks for logger file entries --- host/include/uhd/utils/log.hpp | 17 +++++++++-------- host/lib/utils/log.cpp | 27 +++++++++++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp index 75c335099..b3e88f865 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -48,13 +48,6 @@ * - Example environment variable: export UHD_LOG_LEVEL=regularly */ -/*! - * A UHD logger macro with default verbosity. - * Usage: UHD_LOG << "the log message" << std::endl; - */ -#define UHD_LOG \ - uhd::_log::log(uhd::_log::regularly, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) - /*! * A UHD logger macro with configurable verbosity. * Usage: UHD_LOGV(very_rarely) << "the log message" << std::endl; @@ -62,6 +55,14 @@ #define UHD_LOGV(verbosity) \ uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) +/*! + * A UHD logger macro with default verbosity. + * Usage: UHD_LOG << "the log message" << std::endl; + */ +#define UHD_LOG \ + UHD_LOGV(regularly) + + namespace uhd{ namespace _log{ //! Verbosity levels for the logger @@ -74,7 +75,7 @@ namespace uhd{ namespace _log{ }; //! Internal logging object (called by UHD_LOG macros) - struct UHD_API log{ + struct /*UHD_API*/ log{ log( const verbosity_t verbosity, const std::string &file, diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index 7df077a96..061173d6b 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -142,6 +142,17 @@ UHD_SINGLETON_FCN(uhd_logger_stream_resource_class, uhd_logger_stream_resource); /*********************************************************************** * The logger function implementation **********************************************************************/ +//! get the relative file path from the host directory +static std::string get_rel_file_path(const fs::path &file){ + fs::path abs_path = file.branch_path(); + fs::path rel_path = file.leaf(); + while (not abs_path.empty() and abs_path.leaf() != "host"){ + rel_path = abs_path.leaf() / rel_path; + abs_path = abs_path.branch_path(); + } + return rel_path.string(); +} + uhd::_log::log::log( const verbosity_t verbosity, const std::string &file, @@ -151,18 +162,22 @@ uhd::_log::log::log( uhd_logger_stream_resource().aquire(true); uhd_logger_stream_resource().set_verbosity(verbosity); const std::string time = pt::to_simple_string(pt::microsec_clock::local_time()); - const std::string header = str(boost::format( - "-- %s - lvl %d - %s @ %s:%u" - ) % time % int(verbosity) % function % fs::path(file).leaf() % line); + const std::string header1 = str(boost::format("-- %s - level %d") % time % int(verbosity)); + const std::string header2 = str(boost::format("-- %s") % function).substr(0, 80); + const std::string header3 = str(boost::format("-- %s:%u") % get_rel_file_path(file) % line); + const std::string border = std::string(std::max(std::max(header1.size(), header2.size()), header3.size()), '-'); uhd_logger_stream_resource().get() << std::endl - << std::string(header.size(), '-') << std::endl - << header << std::endl - << std::string(header.size(), '-') << std::endl + << border << std::endl + << header1 << std::endl + << header2 << std::endl + << header3 << std::endl + << border << std::endl ; } uhd::_log::log::~log(void){ + uhd_logger_stream_resource().get() << std::endl; uhd_logger_stream_resource().aquire(false); } -- cgit v1.2.3