|
|
@ -23,6 +23,7 @@ |
|
|
|
|
|
|
|
#include "StructuredLogger.h" |
|
|
|
|
|
|
|
#include <ctime> |
|
|
|
#include <json/json.h> |
|
|
|
|
|
|
|
using namespace std; |
|
|
@ -30,34 +31,38 @@ using namespace std; |
|
|
|
namespace dev |
|
|
|
{ |
|
|
|
|
|
|
|
char const* StructuredLogger::timePointToString(chrono::system_clock::time_point const& _ts) const |
|
|
|
string StructuredLogger::timePointToString(chrono::system_clock::time_point const& _ts) const |
|
|
|
{ |
|
|
|
// not using C++11 std::put_time due to gcc bug
|
|
|
|
// http://stackoverflow.com/questions/14136833/stdput-time-implementation-status-in-gcc
|
|
|
|
|
|
|
|
// TODO: Format it according to Log event Requirements
|
|
|
|
char buffer[64]; |
|
|
|
time_t time = chrono::system_clock::to_time_t(_ts); |
|
|
|
return ctime(&time); |
|
|
|
tm* ptm = localtime(&time); |
|
|
|
if (strftime(buffer, sizeof(buffer), m_timeFormat.c_str(), ptm)) |
|
|
|
return string(buffer); |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
void StructuredLogger::outputJson(Json::Value const* _value, std::string const& _name) const |
|
|
|
void StructuredLogger::outputJson(Json::Value const& _value, std::string const& _name) const |
|
|
|
{ |
|
|
|
Json::Value event; |
|
|
|
event[_name] = _value; |
|
|
|
cout << event; |
|
|
|
cout << event << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void StructuredLogger::logStarting(string const& _clientImpl, const char* _ethVersion) |
|
|
|
void StructuredLogger::logStarting(string const& _clientImpl, const char* _ethVersion) const |
|
|
|
{ |
|
|
|
if (m_enabled) |
|
|
|
{ |
|
|
|
Json::Value event; |
|
|
|
event["comment"] = "one of the first log events, before any operation is started"; |
|
|
|
event["client_implt"] = _clientImpl; |
|
|
|
event["client_impl"] = _clientImpl; |
|
|
|
event["eth_version"] = std::string(_ethVersion); |
|
|
|
event["ts"] = string(timePointToString(std::chrono::system_clock::now())); |
|
|
|
event["ts"] = timePointToString(std::chrono::system_clock::now()); |
|
|
|
|
|
|
|
outputJson(&event, "starting"); |
|
|
|
outputJson(event, "starting"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -74,9 +79,9 @@ void StructuredLogger::logP2PConnected(string const& _id, bi::tcp::endpoint cons |
|
|
|
event["remote_addr"] = addrStream.str(); |
|
|
|
event["remote_id"] = _id; |
|
|
|
event["num_connections"] = Json::Value(_numConnections); |
|
|
|
event["ts"] = string(timePointToString(_ts)); |
|
|
|
event["ts"] = timePointToString(_ts); |
|
|
|
|
|
|
|
outputJson(&event, "p2p.connected"); |
|
|
|
outputJson(event, "p2p.connected"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -91,9 +96,9 @@ void StructuredLogger::logP2PDisconnected(string const& _id, bi::tcp::endpoint c |
|
|
|
event["remote_addr"] = addrStream.str(); |
|
|
|
event["remote_id"] = _id; |
|
|
|
event["num_connections"] = Json::Value(_numConnections); |
|
|
|
event["ts"] = string(timePointToString(chrono::system_clock::now())); |
|
|
|
event["ts"] = timePointToString(chrono::system_clock::now()); |
|
|
|
|
|
|
|
outputJson(&event, "p2p.disconnected"); |
|
|
|
outputJson(event, "p2p.disconnected"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -107,10 +112,10 @@ void StructuredLogger::logMinedNewBlock(string const& _hash, string const& _bloc |
|
|
|
event["block_hash"] = _hash; |
|
|
|
event["block_number"] = _blockNumber; |
|
|
|
event["chain_head_hash"] = _chainHeadHash; |
|
|
|
event["ts"] = string(timePointToString(std::chrono::system_clock::now())); |
|
|
|
event["ts"] = timePointToString(std::chrono::system_clock::now()); |
|
|
|
event["block_prev_hash"] = _prevHash; |
|
|
|
|
|
|
|
outputJson(&event, "eth.miner.new_block"); |
|
|
|
outputJson(event, "eth.miner.new_block"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -125,10 +130,10 @@ void StructuredLogger::logChainReceivedNewBlock(string const& _hash, string cons |
|
|
|
event["block_number"] = _blockNumber; |
|
|
|
event["chain_head_hash"] = _chainHeadHash; |
|
|
|
event["remote_id"] = _remoteID; |
|
|
|
event["ts"] = string(timePointToString(chrono::system_clock::now())); |
|
|
|
event["ts"] = timePointToString(chrono::system_clock::now()); |
|
|
|
event["block_prev_hash"] = _prevHash; |
|
|
|
|
|
|
|
outputJson(&event, "eth.chain.received.new_block"); |
|
|
|
outputJson(event, "eth.chain.received.new_block"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -142,10 +147,10 @@ void StructuredLogger::logChainNewHead(string const& _hash, string const& _block |
|
|
|
event["block_hash"] = _hash; |
|
|
|
event["block_number"] = _blockNumber; |
|
|
|
event["chain_head_hash"] = _chainHeadHash; |
|
|
|
event["ts"] = string(timePointToString(chrono::system_clock::now())); |
|
|
|
event["ts"] = timePointToString(chrono::system_clock::now()); |
|
|
|
event["block_prev_hash"] = _prevHash; |
|
|
|
|
|
|
|
outputJson(&event, "eth.miner.new_block"); |
|
|
|
outputJson(event, "eth.miner.new_block"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -156,9 +161,9 @@ void StructuredLogger::logTransactionReceived(string const& _hash, string const& |
|
|
|
Json::Value event; |
|
|
|
event["tx_hash"] = _hash; |
|
|
|
event["remote_id"] = _remoteId; |
|
|
|
event["ts"] = string(timePointToString(chrono::system_clock::now())); |
|
|
|
event["ts"] = timePointToString(chrono::system_clock::now()); |
|
|
|
|
|
|
|
outputJson(&event, "eth.tx.received"); |
|
|
|
outputJson(event, "eth.tx.received"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|