Add tracing_debug feature to expose teach-me logging configuration#386
Add tracing_debug feature to expose teach-me logging configuration#386
tracing_debug feature to expose teach-me logging configuration#386Conversation
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
tracing_debug feature to expose teach-me logging configuration
|
@copilot clean up the useless tests |
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a tracing_debug feature flag to cargo-near-build that provides a default tracing subscriber configuration for debugging purposes. It enables all --teach-me messages and detailed logging output, matching the behavior of cargo near --teach-me.
Changes:
- Added
tracing_debugfeature flag with optionaltracing-subscriberdependency - Created new
tracing_debugmodule withinit_tracing_debug()function - Updated documentation in README and lib.rs to describe the new feature
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cargo-near-build/src/tracing_debug.rs | New module providing tracing configuration with SimpleFormatter and env filter setup |
| cargo-near-build/src/lib.rs | Exports the new init_tracing_debug function under the tracing_debug feature flag |
| cargo-near-build/Cargo.toml | Adds tracing_debug feature and optional tracing-subscriber dependency |
| README.md | Documents the new debugging feature with usage examples |
| Cargo.lock | Updates dependency tree with tracing-subscriber |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .add_directive(Level::WARN.into()) | ||
| .add_directive("near_teach_me=info".parse()?) | ||
| .add_directive("near_cli_rs=info".parse()?) | ||
| .add_directive("tracing_instrument=info".parse()?); |
There was a problem hiding this comment.
The filter directives are duplicated from cargo-near/src/lib.rs (lines 107-111). While the comment explains this is intentional to avoid dependencies, consider extracting the filter configuration string (e.g., 'near_teach_me=info,near_cli_rs=info,tracing_instrument=info,warn') to a shared constant in a common location to ensure consistency when updates are made.
| struct SimpleFormatter; | ||
|
|
||
| impl<S, N> FormatEvent<S, N> for SimpleFormatter | ||
| where | ||
| S: Subscriber + for<'a> LookupSpan<'a>, | ||
| N: for<'a> FormatFields<'a> + 'static, | ||
| { | ||
| fn format_event( | ||
| &self, | ||
| ctx: &FmtContext<'_, S, N>, | ||
| mut writer: Writer<'_>, | ||
| event: &Event<'_>, | ||
| ) -> std::fmt::Result { | ||
| let level = *event.metadata().level(); | ||
| let (icon, color_code) = match level { | ||
| Level::TRACE => ("TRACE ", "\x1b[35m"), // Magenta | ||
| Level::DEBUG => ("DEBUG ", "\x1b[34m"), // Blue | ||
| Level::INFO => ("", ""), // Default | ||
| Level::WARN => ("Warning ", "\x1b[33m"), // Yellow | ||
| Level::ERROR => ("ERROR ", "\x1b[31m"), // Red | ||
| }; | ||
|
|
||
| write!(writer, "{}├ {}", color_code, icon)?; | ||
| write!(writer, "\x1b[0m")?; | ||
|
|
||
| ctx.field_format().format_fields(writer.by_ref(), event)?; | ||
|
|
||
| writeln!(writer) | ||
| } |
There was a problem hiding this comment.
The SimpleFormatter implementation is duplicated from cargo-near/src/lib.rs. While the comment at line 43-45 acknowledges this, this creates a maintenance burden where changes to formatting in one location must be manually replicated to the other. Consider extracting SimpleFormatter to a shared internal utility crate or module that both cargo-near and cargo-near-build can depend on, even if it's not part of the public API.
Summary: Add
tracing_debugfeature to cargo-near-build ✅This PR successfully implements a new
tracing_debugfeature forcargo-near-buildthat provides a default tracing configuration enabling all--teach-memessages and detailed logging.Changes Made:
tracing_debugfeature flag to cargo-near-build/Cargo.tomlSecurity Summary:
No security vulnerabilities introduced. The changes only add logging configuration using trusted libraries (tracing-subscriber from the Tokio project). The code:
Usage:
Users can now enable detailed build logging by adding the feature to their Cargo.toml:
And initializing it in their code:
This provides the same verbose logging as
cargo near --teach-mefor debugging build scripts and custom tools.Original prompt
cargo-near-buildshould have a defaulttracingconfig exported undertracing_debugfeature #295💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.