log: Prefix log messages with function name if -logsourcelocations is set

This commit is contained in:
practicalswift
2020-08-25 20:22:28 +00:00
parent 29d2aeb4a2
commit b4511e2e2e
8 changed files with 40 additions and 4 deletions

View File

@@ -5,6 +5,7 @@
#include <logging.h>
#include <util/threadnames.h>
#include <util/string.h>
#include <util/time.h>
#include <mutex>
@@ -236,11 +237,15 @@ namespace BCLog {
}
}
void BCLog::Logger::LogPrintStr(const std::string& str)
void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, const int source_line)
{
StdLockGuard scoped_lock(m_cs);
std::string str_prefixed = LogEscapeMessage(str);
if (m_log_sourcelocations && m_started_new_line) {
str_prefixed.insert(0, "[" + RemovePrefix(source_file, "./") + ":" + ToString(source_line) + "] [" + logging_function + "] ");
}
if (m_log_threadnames && m_started_new_line) {
str_prefixed.insert(0, "[" + util::ThreadGetInternalName() + "] ");
}