Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(esp-println): Add timestamp to logging #3194

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AnthonyGrondin
Copy link
Contributor

@AnthonyGrondin AnthonyGrondin commented Mar 2, 2025

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

  • Introduce new timestamp (non-default) feature to enable logging with a timestamp in millis, in the same format as the bootloader. Considering Rust offers no standard way to fetch time through APIs or traits, this new feature requires pulling esp-hal as a dependency.

Testing

I've tested the changes in a local project, and it both build with and without the feature enabled.

@bugadani
Copy link
Contributor

bugadani commented Mar 3, 2025

I'm not against pulling in esp-hal (I am considering requiring an initializer that takes ownership of the peripheral used for logging), but we can do better I think by requiring an extern "Rust" fn _esp_println_timestamp to exist when the timestamp feature is enabled.

@MabezDev
Copy link
Member

MabezDev commented Mar 3, 2025

I'm not against pulling in esp-hal (I am considering requiring an initializer that takes ownership of the peripheral used for logging), but we can do better I think by requiring an extern "Rust" fn _esp_println_timestamp to exist when the timestamp feature is enabled.

I'd much prefer an extern "Rust" call, over depending on esp-hal. One of esp-println's original goals was to be essentially dependency free (for better or for worse, there are limitations and issues with this library because of this goal).

@@ -17,7 +17,7 @@ use esp_hal::timer::timg::TimerGroup;
#[embassy_executor::task]
async fn run() {
loop {
esp_println::println!("Hello world from embassy using esp-hal-async!");
log::info!("Hello world from embassy using esp-hal-async!");
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't change these

Copy link
Contributor

Choose a reason for hiding this comment

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

Or... well, maybe? I would probably expect println! to print the timestamp, but also it can be equally unexpected sometimes...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've wanted to change these to demo the feature, but I can revert them back

@AnthonyGrondin
Copy link
Contributor Author

I've refactored this PR to only provide a hook gated by the timestamp feature (documented) to allow users to provide their own timestamp implementation, without touching to esp-hal

@Dominaezzz
Copy link
Collaborator

Dominaezzz commented Mar 3, 2025

Could this be done easily outside esp-println? It's just a matter of writing a custom logger

I'm thinking of #1843 which was closed because esp-println was meant to stay simple.

- Introduce new `timestamp` feature to enable logging with a timestamp in millis, in the same format as the bootloader.
@bjoernQ
Copy link
Contributor

bjoernQ commented Mar 4, 2025

I'm thinking of #1843 which was closed because esp-println was meant to stay simple.

Generally yes - it should stay simple - but this seems to be simple enough

Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

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

Thanks

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.

5 participants