aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-01-01 16:34:23 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-01-16 00:25:46 +0000
commit5833d66f6540e7b34e10ddef37c2b67bd501994b (patch)
treee4d312059948a0528583e7ea58d2c0b40307a494 /src/common
parenteasylogging++: fix logging with static const header only data members (diff)
downloadmonero-5833d66f6540e7b34e10ddef37c2b67bd501994b.tar.xz
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with a single one, and also adds filename:line and explicit severity levels. Categories may be defined, and logging severity set by category (or set of categories). epee style 0-4 log level maps to a sensible severity configuration. Log files now also rotate when reaching 100 MB. To select which logs to output, use the MONERO_LOGS environment variable, with a comma separated list of categories (globs are supported), with their requested severity level after a colon. If a log matches more than one such setting, the last one in the configuration string applies. A few examples: This one is (mostly) silent, only outputting fatal errors: MONERO_LOGS=*:FATAL This one is very verbose: MONERO_LOGS=*:TRACE This one is totally silent (logwise): MONERO_LOGS="" This one outputs all errors and warnings, except for the "verify" category, which prints just fatal errors (the verify category is used for logs about incoming transactions and blocks, and it is expected that some/many will fail to verify, hence we don't want the spam): MONERO_LOGS=*:WARNING,verify:FATAL Log levels are, in decreasing order of priority: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE Subcategories may be added using prefixes and globs. This example will output net.p2p logs at the TRACE level, but all other net* logs only at INFO: MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE Logs which are intended for the user (which Monero was using a lot through epee, but really isn't a nice way to go things) should use the "global" category. There are a few helper macros for using this category, eg: MGINFO("this shows up by default") or MGINFO_RED("this is red"), to try to keep a similar look and feel for now. Existing epee log macros still exist, and map to the new log levels, but since they're used as a "user facing" UI element as much as a logging system, they often don't map well to log severities (ie, a log level 0 log may be an error, or may be something we want the user to see, such as an important info). In those cases, I tried to use the new macros. In other cases, I left the existing macros in. When modifying logs, it is probably best to switch to the new macros with explicit levels. The --log-level options and set_log commands now also accept category settings, in addition to the epee style log levels.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/dns_utils.cpp3
-rw-r--r--src/common/i18n.cpp3
-rw-r--r--src/common/perf_timer.cpp14
-rw-r--r--src/common/perf_timer.h17
-rw-r--r--src/common/scoped_message_writer.h27
-rw-r--r--src/common/stack_trace.cpp21
-rw-r--r--src/common/util.h2
7 files changed, 54 insertions, 33 deletions
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp
index 35fb9fe6c..2efdcffcd 100644
--- a/src/common/dns_utils.cpp
+++ b/src/common/dns_utils.cpp
@@ -41,6 +41,9 @@
using namespace epee;
namespace bf = boost::filesystem;
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.dns"
+
static boost::mutex instance_lock;
namespace
diff --git a/src/common/i18n.cpp b/src/common/i18n.cpp
index c04790ce6..05eea3b66 100644
--- a/src/common/i18n.cpp
+++ b/src/common/i18n.cpp
@@ -36,6 +36,9 @@
#include "common/util.h"
#include "common/i18n.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "i18n"
+
static const unsigned char qm_magic[16] = {0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95, 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd};
static std::map<std::string,std::string> i18n_entries;
diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp
index d23c9f11d..3b68485d9 100644
--- a/src/common/perf_timer.cpp
+++ b/src/common/perf_timer.cpp
@@ -28,18 +28,22 @@
#include "perf_timer.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "perf"
+
namespace tools
{
-int performance_timer_log_level = 2;
+el::Level performance_timer_log_level = el::Level::Debug;
__thread std::vector<PerformanceTimer*> *performance_timers = NULL;
-void set_performance_timer_log_level(int level)
+void set_performance_timer_log_level(el::Level level)
{
- if (level < LOG_LEVEL_MIN || level > LOG_LEVEL_MAX)
+ if (level != el::Level::Debug && level != el::Level::Trace && level != el::Level::Info
+ && level != el::Level::Warning && level != el::Level::Error && level != el::Level::Fatal)
{
- LOG_PRINT_L0("Wrong log level: " << level << ", using 2");
- level = 2;
+ MERROR("Wrong log level: " << el::LevelHelper::convertToString(level) << ", using Debug");
+ level = el::Level::Debug;
}
performance_timer_log_level = level;
}
diff --git a/src/common/perf_timer.h b/src/common/perf_timer.h
index 5eb5aaaec..56662ff24 100644
--- a/src/common/perf_timer.h
+++ b/src/common/perf_timer.h
@@ -32,23 +32,26 @@
#include <stdio.h>
#include "misc_log_ex.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "perf"
+
namespace tools
{
class PerformanceTimer;
-extern int performance_timer_log_level;
+extern el::Level performance_timer_log_level;
extern __thread std::vector<PerformanceTimer*> *performance_timers;
class PerformanceTimer
{
public:
- PerformanceTimer(const std::string &s, int l = LOG_LEVEL_2): name(s), level(l), started(false)
+ PerformanceTimer(const std::string &s, el::Level l = el::Level::Debug): name(s), level(l), started(false)
{
ticks = epee::misc_utils::get_tick_count();
if (!performance_timers)
{
- LOG_PRINT("PERF ----------", level);
+ MLOG(level, "PERF ----------");
performance_timers = new std::vector<PerformanceTimer*>();
}
else
@@ -56,7 +59,7 @@ public:
PerformanceTimer *pt = performance_timers->back();
if (!pt->started)
{
- LOG_PRINT("PERF " << std::string((performance_timers->size()-1) * 2, ' ') << " " << pt->name, pt->level);
+ MLOG(pt->level, "PERF " << std::string((performance_timers->size()-1) * 2, ' ') << " " << pt->name);
pt->started = true;
}
}
@@ -69,7 +72,7 @@ public:
ticks = epee::misc_utils::get_tick_count() - ticks;
char s[12];
snprintf(s, sizeof(s), "%8llu ", (unsigned long long)ticks);
- LOG_PRINT("PERF " << s << std::string(performance_timers->size() * 2, ' ') << " " << name, level);
+ MLOG(level, "PERF " << s << std::string(performance_timers->size() * 2, ' ') << " " << name);
if (performance_timers->empty())
{
delete performance_timers;
@@ -79,12 +82,12 @@ public:
private:
std::string name;
- int level;
+ el::Level level;
uint64_t ticks;
bool started;
};
-void set_performance_timer_log_level(int level);
+void set_performance_timer_log_level(el::Level level);
#define PERF_TIMER(name) tools::PerformanceTimer pt_##name(#name, tools::performance_timer_log_level)
#define PERF_TIMER_L(name, l) tools::PerformanceTimer pt_##name(#name, l)
diff --git a/src/common/scoped_message_writer.h b/src/common/scoped_message_writer.h
index 77dda7181..f82181926 100644
--- a/src/common/scoped_message_writer.h
+++ b/src/common/scoped_message_writer.h
@@ -34,20 +34,23 @@
namespace tools
{
+/************************************************************************/
+/* */
+/************************************************************************/
class scoped_message_writer
{
private:
bool m_flush;
std::stringstream m_oss;
- epee::log_space::console_colors m_color;
+ epee::console_colors m_color;
bool m_bright;
- int m_log_level;
+ el::Level m_log_level;
public:
scoped_message_writer(
- epee::log_space::console_colors color = epee::log_space::console_color_default
+ epee::console_colors color = epee::console_color_default
, bool bright = false
, std::string&& prefix = std::string()
- , int log_level = LOG_LEVEL_2
+ , el::Level log_level = el::Level::Info
)
: m_flush(true)
, m_color(color)
@@ -88,17 +91,17 @@ public:
{
m_flush = false;
- LOG_PRINT(m_oss.str(), m_log_level);
+ MCLOG(m_log_level, "msgwriter", m_oss.str());
- if (epee::log_space::console_color_default == m_color)
+ if (epee::console_color_default == m_color)
{
std::cout << m_oss.str();
}
else
{
- epee::log_space::set_console_color(m_color, m_bright);
+ set_console_color(m_color, m_bright);
std::cout << m_oss.str();
- epee::log_space::reset_console_color();
+ epee::reset_console_color();
}
std::cout << std::endl;
}
@@ -107,17 +110,17 @@ public:
inline scoped_message_writer success_msg_writer()
{
- return scoped_message_writer(epee::log_space::console_color_green, false, std::string(), LOG_LEVEL_2);
+ return scoped_message_writer(epee::console_color_green, false, std::string(), el::Level::Info);
}
-inline scoped_message_writer msg_writer(epee::log_space::console_colors color = epee::log_space::console_color_default)
+inline scoped_message_writer msg_writer(epee::console_colors color = epee::console_color_default)
{
- return scoped_message_writer(color, false, std::string(), LOG_LEVEL_2);
+ return scoped_message_writer(color, false, std::string(), el::Level::Info);
}
inline scoped_message_writer fail_msg_writer()
{
- return scoped_message_writer(epee::log_space::console_color_red, true, "Error: ", LOG_LEVEL_0);
+ return scoped_message_writer(epee::console_color_red, true, "Error: ", el::Level::Error);
}
} // namespace tools
diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp
index 5bbd3e252..ce05b7e04 100644
--- a/src/common/stack_trace.cpp
+++ b/src/common/stack_trace.cpp
@@ -35,6 +35,11 @@
#include <dlfcn.h>
#endif
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "stacktrace"
+
+#define ST_LOG(x) CERROR(el::base::Writer,el::base::DispatchAction::FileOnlyLog,MONERO_DEFAULT_LOG_CATEGORY) << x
+
// from http://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c
// The decl of __cxa_throw in /usr/include/.../cxxabi.h uses
@@ -103,34 +108,34 @@ void log_stack_trace(const char *msg)
const char *log = stack_trace_log.empty() ? NULL : stack_trace_log.c_str();
if (msg)
- LOG_PRINT2(log, msg, LOG_LEVEL_0);
- LOG_PRINT2(log, "Unwound call stack:", LOG_LEVEL_0);
+ ST_LOG(msg);
+ ST_LOG("Unwound call stack:");
if (unw_getcontext(&ctx) < 0) {
- LOG_PRINT2(log, "Failed to create unwind context", LOG_LEVEL_0);
+ ST_LOG("Failed to create unwind context");
return;
}
if (unw_init_local(&cur, &ctx) < 0) {
- LOG_PRINT2(log, "Failed to find the first unwind frame", LOG_LEVEL_0);
+ ST_LOG("Failed to find the first unwind frame");
return;
}
for (level = 1; level < 999; ++level) { // 999 for safety
int ret = unw_step(&cur);
if (ret < 0) {
- LOG_PRINT2(log, "Failed to find the next frame", LOG_LEVEL_0);
+ ST_LOG("Failed to find the next frame");
return;
}
if (ret == 0)
break;
if (unw_get_reg(&cur, UNW_REG_IP, &ip) < 0) {
- LOG_PRINT2(log, " " << std::setw(4) << level, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level);
continue;
}
if (unw_get_proc_name(&cur, sym, sizeof(sym), &off) < 0) {
- LOG_PRINT2(log, " " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip);
continue;
}
dsym = abi::__cxa_demangle(sym, NULL, NULL, &status);
- LOG_PRINT2(log, " " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off);
free(dsym);
}
}
diff --git a/src/common/util.h b/src/common/util.h
index 501a6d487..4437d821f 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -152,7 +152,7 @@ namespace tools
}
else
{
- LOG_PRINT_RED_L0("Got control signal " << type << ". Exiting without saving...");
+ MGINFO_RED("Got control signal " << type << ". Exiting without saving...");
return FALSE;
}
return TRUE;