Browse Source

StructuredLogging timestamp format is now configurable

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

6
eth/main.cpp

@ -121,6 +121,7 @@ void help()
<< " -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
<< " --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
<< " -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
@ -210,6 +211,7 @@ int main(int argc, char** argv)
bool forceMining = false;
bool jit = false;
bool structuredLogging = false;
string structuredLoggingFormat = "%Y-%m-%dT%H:%M:%S";
string clientName;
// Init defaults
@ -282,6 +284,8 @@ int main(int argc, char** argv)
}
else if ((arg == "-s" || arg == "--secret") && i + 1 < argc)
us = KeyPair(h256(fromHex(argv[++i])));
else if (arg == "--structured-logging-format" && i + 1 < argc)
structuredLoggingFormat = string(argv[++i]);
else if (arg == "--structured-logging")
structuredLogging = true;
else if ((arg == "-d" || arg == "--path" || arg == "--db-path") && i + 1 < argc)
@ -355,7 +359,7 @@ int main(int argc, char** argv)
cout << credits();
StructuredLogger structuredLogger(structuredLogging);
StructuredLogger structuredLogger(structuredLogging, structuredLoggingFormat);
VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter);
NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal);
auto nodesState = contents((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp");

11
libdevcore/StructuredLogger.h

@ -34,11 +34,20 @@ namespace Json { class Value; }
namespace dev
{
// TODO: Make the output stream configurable. stdout, stderr, file e.t.c.
class StructuredLogger
{
public:
/// Default constructor, logging off
StructuredLogger(): m_enabled(false){}
StructuredLogger(bool _enabled, std::string const& _timeFormat = "%Y-%m-%dT%H:%M:%S"):
/**
* 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;

Loading…
Cancel
Save