Skip to content

Commit

Permalink
Merge pull request #1608
Browse files Browse the repository at this point in the history
1e8cc67 mlog: allow using numerical level as default prefix (moneromooo-monero)
8028b53 protocol: log received messages in a separate category (moneromooo-monero)
  • Loading branch information
fluffypony committed Jan 22, 2017
2 parents 9c06a7f + 1e8cc67 commit daf6662
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
62 changes: 37 additions & 25 deletions contrib/epee/src/mlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down
18 changes: 10 additions & 8 deletions src/cryptonote_protocol/cryptonote_protocol_handler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net.cn"

#define MLOG_P2P_MESSAGE(x) MCINFO("net.p2p.msg", context << x)

namespace cryptonote
{

Expand Down Expand Up @@ -314,7 +316,7 @@ namespace cryptonote
template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_notify_new_block(int command, NOTIFY_NEW_BLOCK::request& arg, cryptonote_connection_context& context)
{
LOG_PRINT_CCONTEXT_L2("NOTIFY_NEW_BLOCK (hop " << arg.hop << ")");
MLOG_P2P_MESSAGE("Received NOTIFY_NEW_BLOCK (hop " << arg.hop << ", " << arg.b.txs.size() << " txes)");
if(context.m_state != cryptonote_connection_context::state_normal)
return 1;
m_core.pause_mine();
Expand Down Expand Up @@ -365,7 +367,7 @@ namespace cryptonote
template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_notify_new_fluffy_block(int command, NOTIFY_NEW_FLUFFY_BLOCK::request& arg, cryptonote_connection_context& context)
{
LOG_PRINT_CCONTEXT_L2("NOTIFY_NEW_FLUFFY_BLOCK (hop " << arg.hop << ")");
MLOG_P2P_MESSAGE("Received NOTIFY_NEW_FLUFFY_BLOCK (hop " << arg.hop << ", " << arg.b.txs.size() << " txes)");
if(context.m_state != cryptonote_connection_context::state_normal)
return 1;

Expand Down Expand Up @@ -613,7 +615,7 @@ namespace cryptonote
template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_request_fluffy_missing_tx(int command, NOTIFY_REQUEST_FLUFFY_MISSING_TX::request& arg, cryptonote_connection_context& context)
{
LOG_PRINT_CCONTEXT_L2("NOTIFY_REQUEST_FLUFFY_MISSING_TX");
MLOG_P2P_MESSAGE("Received NOTIFY_REQUEST_FLUFFY_MISSING_TX (" << arg.missing_tx_indices.size() << " txes)");

std::list<block> local_blocks;
std::list<transaction> local_txs;
Expand Down Expand Up @@ -671,7 +673,7 @@ namespace cryptonote
template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_notify_new_transactions(int command, NOTIFY_NEW_TRANSACTIONS::request& arg, cryptonote_connection_context& context)
{
LOG_PRINT_CCONTEXT_L2("NOTIFY_NEW_TRANSACTIONS");
MLOG_P2P_MESSAGE("Received NOTIFY_NEW_TRANSACTIONS (" << arg.txs.size() << " txes)");
if(context.m_state != cryptonote_connection_context::state_normal)
return 1;

Expand Down Expand Up @@ -703,7 +705,7 @@ namespace cryptonote
template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_request_get_objects(int command, NOTIFY_REQUEST_GET_OBJECTS::request& arg, cryptonote_connection_context& context)
{
LOG_PRINT_CCONTEXT_L2("NOTIFY_REQUEST_GET_OBJECTS");
MLOG_P2P_MESSAGE("Received NOTIFY_REQUEST_GET_OBJECTS (" << arg.blocks.size() << " blocks, " << arg.txs.size() << " txes)");
NOTIFY_RESPONSE_GET_OBJECTS::request rsp;
if(!m_core.handle_get_objects(arg, rsp, context))
{
Expand Down Expand Up @@ -743,7 +745,7 @@ namespace cryptonote
template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_response_get_objects(int command, NOTIFY_RESPONSE_GET_OBJECTS::request& arg, cryptonote_connection_context& context)
{
LOG_PRINT_CCONTEXT_L2("NOTIFY_RESPONSE_GET_OBJECTS");
MLOG_P2P_MESSAGE("Received NOTIFY_RESPONSE_GET_OBJECTS (" << arg.blocks.size() << " blocks, " << arg.txs.size() << " txes)");

// calculate size of request - mainly for logging/debug
size_t size = 0;
Expand Down Expand Up @@ -933,7 +935,7 @@ namespace cryptonote
template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_request_chain(int command, NOTIFY_REQUEST_CHAIN::request& arg, cryptonote_connection_context& context)
{
LOG_PRINT_CCONTEXT_L2("NOTIFY_REQUEST_CHAIN: m_block_ids.size()=" << arg.block_ids.size());
MLOG_P2P_MESSAGE("Received NOTIFY_REQUEST_CHAIN (" << arg.block_ids.size() << " blocks");
NOTIFY_RESPONSE_CHAIN_ENTRY::request r;
if(!m_core.find_blockchain_supplement(arg.block_ids, r))
{
Expand Down Expand Up @@ -1048,7 +1050,7 @@ namespace cryptonote
template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_response_chain_entry(int command, NOTIFY_RESPONSE_CHAIN_ENTRY::request& arg, cryptonote_connection_context& context)
{
LOG_PRINT_CCONTEXT_L2("NOTIFY_RESPONSE_CHAIN_ENTRY: m_block_ids.size()=" << arg.m_block_ids.size()
MLOG_P2P_MESSAGE("Received NOTIFY_RESPONSE_CHAIN_ENTRY: m_block_ids.size()=" << arg.m_block_ids.size()
<< ", m_start_height=" << arg.start_height << ", m_total_height=" << arg.total_height);

if(!arg.m_block_ids.size())
Expand Down

0 comments on commit daf6662

Please sign in to comment.