Repository navigation
Add trace function to Logger trait - #4155
Conversation
|
I've added a test which checks the tracing output. I think ideally the assert would be: But that would currently fail due to point 3.2 above, so I've modified the test to make it pass as I don't know if point 3 is easily addressable. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4155 +/- ##
==========================================
+ Coverage 47.24% 54.71% +7.46%
==========================================
Files 476 492 +16
Lines 46892 49402 +2510
==========================================
+ Hits 22154 27029 +4875
+ Misses 24738 22373 -2365 ☔ View full report in Codecov by Sentry. |
TBH, those sound like bugs on |
|
I had a look at the |
jedel1043
left a comment
There was a problem hiding this comment.
Looks pretty nice, thank you for the contribution!
This Pull Request implements the discussion in Matrix about trace logging.
It changes the following:
tracefunction to theLoggertrait.tracefunction fromConsole.trace.For such a small PR, I encountered a few niggles:
1. Conflicting
tracemethodThe
Loggertrait derives from theTracetrait, which already has atracefunction, but is unrelated to trace logging. This meant I had to call the new trace function by doing:rather than the following which is ambiguous to the compiler:
This is unsatisfactory, but I also felt that renaming the new
Logger.tracefunction would make it inconsistent with the surrounding code.2. Passing the stack trace
In matrix we discussed passing the stack trace into the
Logger.tracefunction.Vec<string>of stack frame code block names, but this feels quite prescriptive with the Console deciding in how the stack trace is formatted.Vec<&CallFrame>, but the borrow checker points out that this means I'd be passing in both a mutable reference toContextand immutable references to theCallFrameinstances insideContext.Logger.traceimplementation to extract the call stack fromContextitself, and format the call frames as it sees fit, and it also keeps thetracesignature consistent with the other logging functions.3. Code block names
There were a couple of unexpected things here. If I comment out the
.filter(|name| !name.is_empty())line which I added and run on the following test javascript:I get the following output:
Unexpected things:
console.traceisn't included in the stack trace.I resolved the first by filtering out empty stack frame names, although I didn't love this solution.
I wasn't sure how to resolve the second point.