Browse Source

StructuredLogging timestamp format is now configurable

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
97ab2d6d18
  1. 6
      eth/main.cpp
  2. 13
      libdevcore/StructuredLogger.h

6
eth/main.cpp

@ -121,6 +121,7 @@ void help()
<< " -r,--remote <host> Connect to remote host (default: none)." << endl << " -r,--remote <host> Connect to remote host (default: none)." << endl
<< " -s,--secret <secretkeyhex> Set the secret key for use with send command (default: auto)." << endl << " -s,--secret <secretkeyhex> Set the secret key for use with send command (default: auto)." << endl
<< " --structured-logging Enables structured logging." << endl << " --structured-logging Enables structured logging." << endl
<< " --structured-logging-format <time-format> Give time format string for structured logging output." << endl
<< " -t,--miners <number> Number of mining threads to start (Default: " << thread::hardware_concurrency() << ")" << endl << " -t,--miners <number> Number of mining threads to start (Default: " << thread::hardware_concurrency() << ")" << endl
<< " -u,--public-ip <ip> Force public ip to given (default; auto)." << endl << " -u,--public-ip <ip> Force public ip to given (default; auto)." << endl
<< " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (Default: 8)." << endl << " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (Default: 8)." << endl
@ -210,6 +211,7 @@ int main(int argc, char** argv)
bool forceMining = false; bool forceMining = false;
bool jit = false; bool jit = false;
bool structuredLogging = false; bool structuredLogging = false;
string structuredLoggingFormat = "%Y-%m-%dT%H:%M:%S";
string clientName; string clientName;
// Init defaults // Init defaults
@ -282,6 +284,8 @@ int main(int argc, char** argv)
} }
else if ((arg == "-s" || arg == "--secret") && i + 1 < argc) else if ((arg == "-s" || arg == "--secret") && i + 1 < argc)
us = KeyPair(h256(fromHex(argv[++i]))); us = KeyPair(h256(fromHex(argv[++i])));
else if (arg == "--structured-logging-format" && i + 1 < argc)
structuredLoggingFormat = string(argv[++i]);
else if (arg == "--structured-logging") else if (arg == "--structured-logging")
structuredLogging = true; structuredLogging = true;
else if ((arg == "-d" || arg == "--path" || arg == "--db-path") && i + 1 < argc) else if ((arg == "-d" || arg == "--path" || arg == "--db-path") && i + 1 < argc)
@ -355,7 +359,7 @@ int main(int argc, char** argv)
cout << credits(); cout << credits();
StructuredLogger structuredLogger(structuredLogging); StructuredLogger structuredLogger(structuredLogging, structuredLoggingFormat);
VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter); VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter);
NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal); NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal);
auto nodesState = contents((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp"); auto nodesState = contents((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp");

13
libdevcore/StructuredLogger.h

@ -34,12 +34,21 @@ namespace Json { class Value; }
namespace dev namespace dev
{ {
// TODO: Make the output stream configurable. stdout, stderr, file e.t.c.
class StructuredLogger class StructuredLogger
{ {
public: public:
/// Default constructor, logging off
StructuredLogger(): m_enabled(false){} StructuredLogger(): m_enabled(false){}
StructuredLogger(bool _enabled, std::string const& _timeFormat = "%Y-%m-%dT%H:%M:%S"): /**
m_enabled(_enabled), m_timeFormat(_timeFormat) {} * Initializes a structured logger object
* @param _enabled Whether logging is on or off
* @param _timeFormat A time format string as described here:
* http://en.cppreference.com/w/cpp/chrono/c/strftime
* with which to display timestamps
*/
StructuredLogger(bool _enabled, std::string const& _timeFormat):
m_enabled(_enabled), m_timeFormat(_timeFormat) {}
void logStarting(std::string const& _clientImpl, const char* _ethVersion) const; void logStarting(std::string const& _clientImpl, const char* _ethVersion) const;
void logP2PConnected(std::string const& _id, bi::tcp::endpoint const& _addr, void logP2PConnected(std::string const& _id, bi::tcp::endpoint const& _addr,

Loading…
Cancel
Save