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

custom logger #1200

Open
plebhash opened this issue Oct 10, 2024 · 6 comments
Open

custom logger #1200

plebhash opened this issue Oct 10, 2024 · 6 comments
Labels
low-prio protocols Lowest level protocol logic

Comments

@plebhash
Copy link
Collaborator

background

protocols crates should use as little external dependencies as possible.

problem

currently, the following crates use tracing as an external dependency:

solution

write a custom logger to replace tracing

reference from rust-lightning: https://github.com/lightningdevkit/rust-lightning/blob/f94bf9861289ce6a75fd7d5856d736a2f966a619/lightning/src/util/logger.rs#L165

@plebhash plebhash added the protocols Lowest level protocol logic label Oct 10, 2024
@Fi3
Copy link
Collaborator

Fi3 commented Oct 11, 2024

tracing is kinda of the standard for logging, every project that will use the library will very likely expect to have log reported by tracing, is also audited by google. https://github.com/google/rust-crate-audits/blob/main/manual-sources/google3-audits.toml#L1383

I don't think that we should remove it, if there is a way to do that without disrupting the user experience could make sense. If not no.

@Shourya742
Copy link
Contributor

@plebhash
Copy link
Collaborator Author

plebhash commented Jan 10, 2025

I should probably clarify that I only created this issue to take note of some discussion point we had in a call last year

even though we try to use as little external dependencies as possible (to avoid introducing vulnerabilities etc), tracing is a widely used crate, and as @Fi3 pointed out it's extensively audited and therefore I don't see this dependency as a critical point of vulnerability

therefore I don't think this is high priority

@Shourya742
Copy link
Contributor

I have implemented a custom logger, which can be found here: https://github.com/Shourya742/logger. I'm leaving this comment in case we might need it in the future.

@plebhash
Copy link
Collaborator Author

@Georges760 please write an explanation of how embedded systems manage logging

@Georges760
Copy link
Contributor

@Georges760 please write an explanation of how embedded systems manage logging

In embedded systems, logging is usually done using defmt crate (more info here), it permit "deferred formatting", so the microcontroler does not have to manipulate utf8 strings and send them to the host debugger !

Most of the libraries that want to support embedded system have a feature defmt or often defmt-03 that

  • enable the optional dependancy (ex serde-json-core)
  • propagate to dep with defmt support
  • add #[cfg_attr(feature = "defmt-03", derive(defmt::Format))] to pub struct/enum of the crate (ex serde-json-core)

As defmt optimization rely on linker time specific, it MUST be opt-in for a library (so does any logging system IMHO to let the library user choose which logging system to use).

As an example, in bm13xx-rs crates, I have support for 2 logging systems: defmt (for embedded) or log (for std), and have an abstraction here so the code can use the usual debug!() and other info!()`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low-prio protocols Lowest level protocol logic
Projects
None yet
Development

No branches or pull requests

4 participants