Skip to content

internal logging macros#155

Merged
tommasoclini merged 3 commits intojamesmunns:mainfrom
tommasoclini:main
Nov 7, 2025
Merged

internal logging macros#155
tommasoclini merged 3 commits intojamesmunns:mainfrom
tommasoclini:main

Conversation

@tommasoclini
Copy link
Copy Markdown
Collaborator

Make ergot use the internal logger when using the log crate by using wrapper macros.

@tommasoclini tommasoclini requested a review from Copilot October 28, 2025 08:50

This comment was marked as resolved.

#[cfg(not(all(feature = "defmt-v1", not(feature = "std"))))]
macro_rules! error {
// error!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
// error!(target: "my_target", "a {} event", "log")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These macro wrappers are really cool but it might be nice to document (in natural language) how this is meant to mimic defmt's spec.
I'm sort of torn on the comments - ordinarily in an std environment I'd say this is the perfect place to replace them with some doctests, but I'm not entirely sure how those work (or don't) on no-std projects. Either way I'd favor actual usage examples than standalone comments :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

To be honest I just copy pasted the comments from the official log macros 😅, as of now it's just a prototype, it definetely needs to be reviewed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm sort of torn on the comments - ordinarily in an std environment I'd say this is the perfect place to replace them with some doctests, but I'm not entirely sure how those work (or don't) on no-std projects.

Doc tests (usually) run on the compiler host (so probably x86_64, or arm64), so considering that ergot runs both on microcontroller as well as normal PCs, running the doc tests shouldn't be a problem.

In most cases the consideration is on whether it is too much setup or not, which shouldn't be a problem in this case I think.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think the best way to demonstrate this functionality is with a fully fledged example.
What do you guys think would be the best way to do that?
One simple thing is to use a nop logger in the log-router-serial example, so that ergot's logs are not emitted.

this is needed to not conflict with std applications that don't need
embassy-time, which is needed only by the embassy-usb-v0_5 interface
implementation
@tommasoclini tommasoclini merged commit c1075e2 into jamesmunns:main Nov 7, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants