diff options
author | James Feist <james.feist@linux.intel.com> | 2019-07-08 20:26:14 +0300 |
---|---|---|
committer | James Feist <james.feist@linux.intel.com> | 2019-07-09 19:39:17 +0300 |
commit | a0dba0f7987d88898eae3fa253bd068fc8b9dc67 (patch) | |
tree | 2d8d6bbc4b56dcf9a3dc515182d211a6af1ffdbe | |
parent | 12c04ef5d04d62fd7b19506faf4eb2b08662e979 (diff) | |
download | bmcweb-a0dba0f7987d88898eae3fa253bd068fc8b9dc67.tar.xz |
Add __FILE__ and __LINE__ to log prints
Some error prints are nondescriptive and this helps
tell where the error happened
Tested: Compiled with debug and saw error prints with
filename and line number.
Jul 08 18:52:26 intel-obmc bmcweb[1348]: (2019-07-08 18:52:26) [INFO "webserver_main.cpp":95] bmcweb (Jul 8 2019: 19:24:43)
Jul 08 18:52:26 intel-obmc bmcweb[1348]: (2019-07-08 18:52:26) [INFO "webserver_main.cpp":34] attempting systemd socket activation
Jul 08 18:52:26 intel-obmc bmcweb[1348]: (2019-07-08 18:52:26) [INFO "webserver_main.cpp":38] Starting webserver on socket handle 3
Jul 08 18:52:28 intel-obmc bmcweb[1348]: (2019-07-08 18:52:28) [INFO "http_server.h":182] Building SSL Context file="/etc/ssl/certs/https/server.pem"
Jul 08 18:52:28 intel-obmc bmcweb[1348]: Checking certs in file /etc/ssl/certs/https/server.pem
Jul 08 18:52:28 intel-obmc bmcweb[1348]: Found an EC key
Jul 08 18:52:28 intel-obmc bmcweb[1348]: (2019-07-08 18:52:28) [INFO "app.h":186] app::ssl context use_count=2
Jul 08 18:52:28 intel-obmc bmcweb[1348]: (2019-07-08 18:52:28) [INFO "http_server.h":157] iBMC server is running, local endpoint [::]:443
Jul 08 18:52:28 intel-obmc bmcweb[1348]: (2019-07-08 18:52:28) [DEBUG "http_connection.h":267] 0xb43b48 Connection open, total 1
Change-Id: I9838d1863bcdd2d8401d3237729a8e7f134bfd07
Signed-off-by: James Feist <james.feist@linux.intel.com>
-rw-r--r-- | crow/include/crow/logging.h | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/crow/include/crow/logging.h b/crow/include/crow/logging.h index 9da47b733a..1d4de57670 100644 --- a/crow/include/crow/logging.h +++ b/crow/include/crow/logging.h @@ -3,6 +3,7 @@ #include <cstdio> #include <cstdlib> #include <ctime> +#include <filesystem> #include <iostream> #include <sstream> #include <string> @@ -63,10 +64,14 @@ class logger } public: - logger(const std::string& prefix, LogLevel level) : level(level) + logger(const std::string& prefix, const std::string& filename, + const size_t line, LogLevel level) : + level(level) { #ifdef BMCWEB_ENABLE_LOGGING - stringstream << "(" << timestamp() << ") [" << prefix << "] "; + stringstream << "(" << timestamp() << ") [" << prefix << " " + << std::filesystem::path(filename).filename() << ":" + << line << "] "; #endif } ~logger() @@ -130,16 +135,16 @@ class logger #define BMCWEB_LOG_CRITICAL \ if (crow::logger::get_current_log_level() <= crow::LogLevel::Critical) \ - crow::logger("CRITICAL", crow::LogLevel::Critical) + crow::logger("CRITICAL", __FILE__, __LINE__, crow::LogLevel::Critical) #define BMCWEB_LOG_ERROR \ if (crow::logger::get_current_log_level() <= crow::LogLevel::Error) \ - crow::logger("ERROR ", crow::LogLevel::Error) + crow::logger("ERROR", __FILE__, __LINE__, crow::LogLevel::Error) #define BMCWEB_LOG_WARNING \ if (crow::logger::get_current_log_level() <= crow::LogLevel::Warning) \ - crow::logger("WARNING ", crow::LogLevel::Warning) + crow::logger("WARNING", __FILE__, __LINE__, crow::LogLevel::Warning) #define BMCWEB_LOG_INFO \ if (crow::logger::get_current_log_level() <= crow::LogLevel::Info) \ - crow::logger("INFO ", crow::LogLevel::Info) + crow::logger("INFO", __FILE__, __LINE__, crow::LogLevel::Info) #define BMCWEB_LOG_DEBUG \ if (crow::logger::get_current_log_level() <= crow::LogLevel::Debug) \ - crow::logger("DEBUG ", crow::LogLevel::Debug) + crow::logger("DEBUG", __FILE__, __LINE__, crow::LogLevel::Debug) |