Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Eth c++ client structured logging #1169

Merged
merged 17 commits into from
Mar 4, 2015

Conversation

LefterisJP
Copy link
Contributor

Implementing the Structured Logging Spec for the C++ client.

  • Some fields are missing since I am not 100% familiar with that part of the codebase but I am positive with some quick feedback they will filled in fast.
  • At the moment starting the client with ./eth/eth --structured-logging will enable structured logging.
    A nice bonus is that with the --structured-logging-format <%Y-%m-%d> we can give a strftime() type of format string to influence the way timestamps are printed.
  • I took the liberty of adding a Stop log event when the client shuts down. I think it would be needed.
  • Finally I apologize for "infecting" the PR with style fixes but I tried to follow the style guide as I was touching the code here and there.

if (m_enabled)
{
Json::Value event;
event["comment"] = "one of the first log events, before any operation is started";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik this isn't implemented in the client and can be removed.

@subtly
Copy link
Member

subtly commented Mar 2, 2015

This CLI parameters are okay. Instead of creating a new class for this please look at the existing logging implementation and build on those. Would recommend creating a StructuredLogOutputStream similar to LogOutputStream; remove operator<<, add a log(string&,unsigned) and log(string&,string&), and replace m_sstr with Json::Value m_event. Set fwd declration for Json::Value in Log.h and implement log() in Log.cpp so we don't have to change includes in every file.

@LefterisJP
Copy link
Contributor Author

I can understand the thread safety argument, but I really strongly believe that it should stay a separate class as it is right now.

I really don't like the idea of making another LogOutputStream. These 2 different kinds of logging systems serve totally different purposes. I will add a mutex to the current class to protect the output as the one in LogOutputStream does.

@LefterisJP LefterisJP force-pushed the eth_StructuredLogging branch from dc90863 to 5b28246 Compare March 2, 2015 10:49
@LefterisJP
Copy link
Contributor Author

rebased

@LefterisJP
Copy link
Contributor Author

The 2 fields missing from the logging for now are:

  • chain head hash from eth.miner.new_block event
  • remote id from eth.chain.received.new_block event


void starting(std::string const& _clientImpl, const char* _ethVersion) const;
void stopping(std::string const& _clientImpl, const char* _ethVersion) const;
void p2pConnected(std::string const& _id, bi::tcp::endpoint const& _addr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style is incorrect. see latest CodingStandards.txt, 0.a and the golden rule.

@LefterisJP LefterisJP force-pushed the eth_StructuredLogging branch from f8b4b3c to 17281c1 Compare March 2, 2015 23:27
@LefterisJP
Copy link
Contributor Author

Can anyone try to build this locally? I have no idea why buildbot fails to find json/json.h. It makes no sense. We use it in other files too.

@onepremise
Copy link
Contributor

I've seen this happen before with builds which reference jsoncpp in nonstandard path. I had to explicitly include jsoncpp before /usr/include because it was getting confused with distros that have the standard jsonc library installed, "-I/include/jsoncpp -I/include". You could try changing '#include json/json.h" to "#include jsoncpp/json/json.h". That is if the build machine was recently updated and jsoncpp is now in the path it's usually installed at on most distributions.

@LefterisJP
Copy link
Contributor Author

I see. Thanks for the info @onepremise. I'd rather not have to do black magic to appease the buildbot though.

Found it out. Seems CMakeLists.txt needed the jsoncpp headers location specified too. In my machine jsoncpp headers were added in /usr/include so no special config was required. The build should be fixed for the PR now.

@LefterisJP LefterisJP force-pushed the eth_StructuredLogging branch from f72ae5c to e44ab45 Compare March 3, 2015 14:36
@onepremise
Copy link
Contributor

 I'd rather not have to do black magic to appease the buildbot 

LefterisJP, wasn't trying to point this out as a 'black magic' fix. It really is a distribution issue. Most linux distros will have installs which deploy to /usr/include/json and /usr/include/jsoncpp. If you include in your source files, '#include json/json.h', there's no guarantee that others will be able to build your project without encountering this same issue. I know i did when i started building cpp-ethereum. They will have to explicitly know to include jsonccp first in their include path before this succeeds, that is if they have both jsonc and jsoncpp installed. Many open source projects have deferred to referencing jsoncpp in their source files to avoid this issue. Others, using cmake, have updated their FindJsoncpp.cmake file to search for features.h instead of json.h:

http://stackoverflow.com/questions/18005880/how-to-writing-a-cmake-module-for-jsoncpp

Luckily your buildbot environment isolates the issue.

@LefterisJP
Copy link
Contributor Author

This is why we have cmake. The fix was to adjust the cmakefile for libdevcore. All seems to be sorted.

I did not want any discrepancies between source files. All of our jsoncpp includes should be json/json.h and let cmake sort out the rest.

@@ -103,7 +103,10 @@ class WebThreeDirect : public WebThreeNetworkFace
public:
/// Constructor for private instance. If there is already another process on the machine using @a _dbPath, then this will throw an exception.
/// ethereum() may be safely static_cast()ed to a eth::Client*.
WebThreeDirect(std::string const& _clientVersion, std::string const& _dbPath, bool _forceClean = false, std::set<std::string> const& _interfaces = {"eth", "shh"}, p2p::NetworkPreferences const& _n = p2p::NetworkPreferences(), bytesConstRef _network = bytesConstRef(), int miners = -1);
WebThreeDirect(std::string const& _clientVersion, std::string const& _dbPath, bool _forceClean = false,
std::set<std::string> const& _interfaces = {"eth", "shh"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style (one indent only)

@gavofyork
Copy link
Contributor

style fixes needed. simple rule: if an expression goes on multiple lines, it's always:

PRE
    PART1 SEP
    PART2 SEP
    PART3 SEP
    ...
POST

note, this is not:

PRE PART1 SEP
    PART2 SEP
    PART3 SEP
    ...
POST

nor

PRE PART1 SEP PART2 SEP
    PART3 SEP ...
POST

SEP is ,, ; &c.

PARTs are arguments, initialiser lines &c.

@@ -103,7 +103,14 @@ class WebThreeDirect : public WebThreeNetworkFace
public:
/// Constructor for private instance. If there is already another process on the machine using @a _dbPath, then this will throw an exception.
/// ethereum() may be safely static_cast()ed to a eth::Client*.
WebThreeDirect(std::string const& _clientVersion, std::string const& _dbPath, bool _forceClean = false, std::set<std::string> const& _interfaces = {"eth", "shh"}, p2p::NetworkPreferences const& _n = p2p::NetworkPreferences(), bytesConstRef _network = bytesConstRef(), int miners = -1);
WebThreeDirect(
std::string const& _clientVersion, std::string const& _dbPath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two items on one line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrggh sorry

@LefterisJP LefterisJP force-pushed the eth_StructuredLogging branch from a2cb12d to 5f191f4 Compare March 3, 2015 16:12
}
}

void StructuredLogger::chainReceivedNewBlock(string const& _hash,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still wrong.

gavofyork pushed a commit that referenced this pull request Mar 4, 2015
@gavofyork gavofyork merged commit 10839cf into ethereum:develop Mar 4, 2015
@LefterisJP LefterisJP deleted the eth_StructuredLogging branch June 24, 2015 08:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants