aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/utils/log.cpp
diff options
context:
space:
mode:
authorAndrej Rode <andrej.rode@ettus.com>2017-04-06 11:53:33 -0700
committerMartin Braun <martin.braun@ettus.com>2017-04-07 14:54:03 -0700
commit543c8c40f1aab7e7c394af4e1195a722fa0a047e (patch)
tree10f073f955bad0295aa9756967d150f0917fd055 /host/lib/utils/log.cpp
parent282d57591b2e9befaff667dc9ab2febabcd61e93 (diff)
downloaduhd-543c8c40f1aab7e7c394af4e1195a722fa0a047e.tar.gz
uhd-543c8c40f1aab7e7c394af4e1195a722fa0a047e.tar.bz2
uhd-543c8c40f1aab7e7c394af4e1195a722fa0a047e.zip
utils: add coloring depending on loglevel to console output
Diffstat (limited to 'host/lib/utils/log.cpp')
-rw-r--r--host/lib/utils/log.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp
index 60614d29e..42219e925 100644
--- a/host/lib/utils/log.cpp
+++ b/host/lib/utils/log.cpp
@@ -30,6 +30,35 @@ namespace fs = boost::filesystem;
namespace pt = boost::posix_time;
namespace ip = boost::interprocess;
+static const std::string PURPLE = "\033[35;1m"; // purple
+static const std::string BLUE = "\033[34;1m"; // blue
+static const std::string GREEN = "\033[32;1m"; // green
+static const std::string YELLOW = "\033[33;1m"; // yellow
+static const std::string RED = "\033[31;0m"; // red
+static const std::string BRED = "\033[31;1m"; // bright red
+static const std::string RESET_COLORS = "\033[39;0m"; // reset colors
+
+
+static const std::string verbosity_color(const uhd::log::severity_level &level){
+ switch(level){
+ case (uhd::log::trace):
+ return PURPLE;
+ case(uhd::log::debug):
+ return BLUE;
+ case(uhd::log::info):
+ return GREEN;
+ case(uhd::log::warning):
+ return YELLOW;
+ case(uhd::log::error):
+ return RED;
+ case(uhd::log::fatal):
+ return BRED;
+ default:
+ return RESET_COLORS;
+ }
+}
+
+
/***********************************************************************
* Global resources for the logger
**********************************************************************/
@@ -152,6 +181,7 @@ inline std::string path_to_filename(std::string path)
return path.substr(path.find_last_of("/\\") + 1);
}
+
uhd::_log::log::log(
const uhd::log::severity_level verbosity,
const std::string &file,
@@ -181,6 +211,9 @@ uhd::_log::log::log(
const std::string time = pt::to_simple_string(pt::microsec_clock::local_time());
#endif
_console
+#ifdef UHD_LOG_CONSOLE_COLOR
+ << verbosity_color(verbosity)
+#endif
#ifdef UHD_LOG_CONSOLE_TIME
<< "[" << time << "] "
#endif
@@ -192,6 +225,9 @@ uhd::_log::log::log(
#endif
<< "[" << verbosity << "] "
<< "[" << component << "] "
+#ifdef UHD_LOG_CONSOLE_COLOR
+ << RESET_COLORS
+#endif
;
}
#endif
@@ -225,7 +261,6 @@ uhd::_log::log::~log(void)
<< "Logging has been disabled for this process" << std::endl
;
}
-
}
}