feat: logs filter - #95
Conversation
gmelodie
left a comment
There was a problem hiding this comment.
reviewing as i was almost done before it got converted back
| fprintf(stderr, "Failed to disable libp2p logs: %s\n", | ||
| logRes.error.c_str()); | ||
| return 1; | ||
| } |
There was a problem hiding this comment.
If we get rid of the #ifdef..#endif stuff from above:
| } | |
| node.setLogLevel(LogLevel::None); |
There was a problem hiding this comment.
hmm i don't see what #ifdef..#endif has to do with this code?
result from setLogLevel has to be checked because cbind returns result.
There was a problem hiding this comment.
I guess the overall issue here is that set log level is creating ctx? Why is that. I would expect setLogLevel to never fail (i.e. do not create a context, require one and that's it).
This would keep us from doing
if (!logRes.success) {
fprintf(stderr, "Failed to disable libp2p logs: %s\n",
logRes.error.c_str());
return 1;
}every time
There was a problem hiding this comment.
^ this is setLogLevel from cbind. that setLogLevel returns results, so this result has to be checked. this is what we are doing here when checking result.
There was a problem hiding this comment.
pr #2899 makes setLogLevel a static function. this change requires that call sites continue to check the result, despite avoiding the context.
There was a problem hiding this comment.
there is no validation when setting log lvl anymore, therefore no result (response).
validation is done on cbind side before libp2p node is created.
in logos module it will be impossible to set invalid value, as user will have to use LogLevel enum.
| inputs = { | ||
| logos-module-builder.url = "github:logos-co/logos-module-builder"; | ||
| libp2p.url = "github:vacp2p/nim-libp2p/fix/cbind/nim-ffi-bump"; | ||
| libp2p.url = "github:vacp2p/nim-libp2p/master"; |
There was a problem hiding this comment.
don't fix this to master, as changes can spill here unexpectedly
| libp2p.url = "github:vacp2p/nim-libp2p/master"; | |
| libp2p.url = "github:vacp2p/nim-libp2p/fix/cbind/nim-ffi-bump"; |
or the commit that was merged in master
| libp2p.url = "github:vacp2p/nim-libp2p/master"; | |
| libp2p.url = "github:vacp2p/nim-libp2p/a760255635529adbc2e8f198b8b53ba13396c4ec"; |
There was a problem hiding this comment.
changes can't spill here unexpectedly as it is fixed to master, with rev a70c615c287a94e1134f45c05c18c338c7a3bc8f.
There was a problem hiding this comment.
Yes! but when doing nix flake update to update some other dep this will also update nim-libp2p to latest master, which might not be what we want
There was a problem hiding this comment.
why would it be okay for other deps and not for nim-libp2p dep?
There was a problem hiding this comment.
Let's say we need to update logos core, but nim-libp2p has some breaking changes that have not been ported to cbind yet.
There was a problem hiding this comment.
nim-libp2p has some breaking changes that have not been ported to cbind yet
could never happen. every push to nim-libp2p master has to pass CI. if nim-libp2p code brakes cbind CI that PR will not get through.
ether way, even when we assume that, that case can happen, those are exceptional cases. meaning that by default we want default behavior, which is nix flake update to updated everything. and exceptional cases are dealt with an exception. in this hypothetical case, one would still do nix flake update and manually rivert changes related to nim-libp2p.
|
hmmm i still see logs in tutorials... draft again |
| if (!ctx) { | ||
| auto created = createContext(); | ||
| if (!created.success) return created; | ||
| } | ||
| return callSync("Failed to set log level", [&](SyncPromise* p) { | ||
| return libp2p_ctx_set_log_level(ctx, static_cast<int64_t>(level), | ||
| &Libp2pModuleImpl::cbBool, p); |
There was a problem hiding this comment.
@gmelodie with nim-ffi, is it always required to have a context? I am wondering if we could just update nim-libp2p libp2pSetLogLevel function so it looks like:
proc libp2pSetLogLevel*(level: int): Future[Result[bool, string]] {.ffi.} =
## Changes the process-wide Chronicles runtime log level.
if level < ord(low(chronicles.LogLevel)) or level > ord(high(chronicles.LogLevel)):
return err("invalid log level: " & $level)
when chronicles.runtimeFilteringEnabled:
chronicles.setLogLevel(chronicles.LogLevel(level))
ok(true)
else:
err("Chronicles runtime filtering is disabled")and that way you avoid allocating memory for context and also breaking createNode.
There was a problem hiding this comment.
Yes it should be possible to just do that
There was a problem hiding this comment.
yeah, this will make things better. i'll push this to nim-libp2p
There was a problem hiding this comment.
LogLevel is now passed via config, avoiding need for context.
| In your own application, `LogLevel::Error` or `LogLevel::Fatal` is often a | ||
| useful default. It keeps normal output quiet while still surfacing conditions | ||
| that may indicate libp2p is misbehaving or that your integration code needs an | ||
| adjustment. Some error logs describe remote-peer behavior, retries, or | ||
| recoverable internal state, so they may not require any action from your side. |
There was a problem hiding this comment.
added this as a practical suggestion because users should not generally disable logs completely, especially while building or integrating an application.
still not fully sure this should be the final recommendation, because libp2p logs are not currently structured in a way that is consistently helpful to end users. there are cases where an error log may be written to stdout, but the condition is not necessarily actionable for the application. in some cases, the log level appears to be error mainly because the log statement is inside an except SomeError block.
second reason for adding this note is to raise the topic of improving (more accurately creating) a systematic approach to choosing log levels. runtime logging should be treated as a library feature with user-facing behavior. and now when we are not only a developers, but users as well, it may be easier for us to understand how to approach this.
this may also expand the scope of the commitment ift-ts:p2p:ift:2026q3-nimlibp2p-log-noise-reduction:logging-changes.
.... but it might be completely unnecessary in age of ai. but even with this assumption systematic approach would be useful to ai.

closes: #79