summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-05-04 14:33:35 -0700
committerJosh Blum <josh@joshknows.com>2011-05-04 14:34:57 -0700
commit94399062713a76a42f269a7ed4d3737ecd6ed5cf (patch)
tree2c9943d0ac8133717f1c63fd5432de110db490c7
parent0de4f165e937168693ac758239d569a2ace60325 (diff)
downloaduhd-94399062713a76a42f269a7ed4d3737ecd6ed5cf.tar.gz
uhd-94399062713a76a42f269a7ed4d3737ecd6ed5cf.tar.bz2
uhd-94399062713a76a42f269a7ed4d3737ecd6ed5cf.zip
uhd: tweaks for logger file entries
-rw-r--r--host/include/uhd/utils/log.hpp17
-rw-r--r--host/lib/utils/log.cpp27
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
@@ -49,19 +49,20 @@
*/
/*!
- * 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;
*/
#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);
}