aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-01-22 10:34:13 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-01-22 16:54:17 +0000
commit1e8cc6764e7c814118ac5078faebc8735d4d3597 (patch)
tree751fd63e9bba03f24e948fd7c8236d6ff5e7cae9 /contrib
parentprotocol: log received messages in a separate category (diff)
downloadmonero-1e8cc6764e7c814118ac5078faebc8735d4d3597.tar.xz
mlog: allow using numerical level as default prefix
eg, 2,foo:ERROR,bar:INFO
Diffstat (limited to 'contrib')
-rw-r--r--contrib/epee/src/mlog.cpp62
1 files changed, 37 insertions, 25 deletions
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp
index 4e4217210..139e7b7d6 100644
--- a/contrib/epee/src/mlog.cpp
+++ b/contrib/epee/src/mlog.cpp
@@ -108,6 +108,32 @@ void mlog_configure(const std::string &filename_base, bool console)
mlog_set_categories(monero_log);
}
+static const char *get_default_categories(int level)
+{
+ const char *categories = "";
+ switch (level)
+ {
+ case 0:
+ categories = "*:FATAL,net*:FATAL,global:INFO,verify:FATAL,stacktrace:INFO";
+ break;
+ case 1:
+ categories = "*:WARNING,global:INFO,stacktrace:INFO";
+ break;
+ case 2:
+ categories = "*:DEBUG";
+ break;
+ case 3:
+ categories = "*:TRACE";
+ break;
+ case 4:
+ categories = "*:TRACE";
+ break;
+ default:
+ break;
+ }
+ return categories;
+}
+
void mlog_set_categories(const char *categories)
{
el::Loggers::setCategories(categories);
@@ -117,30 +143,9 @@ void mlog_set_categories(const char *categories)
// maps epee style log level to new logging system
void mlog_set_log_level(int level)
{
- const char *settings = NULL;
- switch (level)
- {
- case 0:
- settings = "*:FATAL,net*:FATAL,global:INFO,verify:FATAL,stacktrace:INFO";
- break;
- case 1:
- settings = "*:WARNING,global:INFO,stacktrace:INFO";
- break;
- case 2:
- settings = "*:DEBUG";
- break;
- case 3:
- settings = "*:TRACE";
- break;
- case 4:
- settings = "*:TRACE";
- break;
- default:
- return;
- }
-
- el::Loggers::setCategories(settings);
- MINFO("Mew log categories: " << settings);
+ const char *categories = get_default_categories(level);
+ el::Loggers::setCategories(categories);
+ MINFO("Mew log categories: " << categories);
}
void mlog_set_log(const char *log)
@@ -151,7 +156,14 @@ void mlog_set_log(const char *log)
level = strtoll(log, &ptr, 10);
if (ptr && *ptr)
{
- mlog_set_categories(log);
+ // we can have a default level, eg, 2,foo:ERROR
+ if (*ptr == ',') {
+ std::string new_categories = std::string(get_default_categories(level)) + ptr;
+ mlog_set_categories(new_categories.c_str());
+ }
+ else {
+ mlog_set_categories(log);
+ }
}
else if (level >= 0 && level <= 4)
{