aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to '')
-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;