Skip to content

Compatibility for log logging macros? #149

@birkenfeld

Description

@birkenfeld

While defmt is shaping up great for embedded logging, the nice thing about the normal log macros is that they can be used in code that's used both in embedded and non-embedded contexts, such as:

  • Nontrivial libraries like smoltcp that are used in both contexts, where high-bandwidth logging is desirable in both cases.

  • Parts of a firmware that are used non-embedded for testing and simulation purposes. It can be quite time saving to extract the hardware independent parts into a library crate, where they can be tested on normal CI infrastructure, and used to simulate the firmware's behavior.

In both cases, using defmt would make this cumbersome, needing to make the logging conditional somehow.

I'm opening this issue for a discussion if it is possible to provide, as a part of defmt, a shim that would keep logging usable for both contexts, with acceptable restrictions. The first thing coming to mind is a macro that makes a transformation like this:

debug!("{:u16} and {:str}", a, b);

=>

#[cfg(not(feature = "defmt-to-log"))]
defmt::debug!("{:u16} and {:str}", a, b);
#[cfg(feature = "defmt-to-log")]
log::debug!("{} and {}", a, b);

i.e. the format string is rewritten for log and the two versions emitted side by side. Of course this can't expect to deliver the same output for all cases (bitfields come to mind), but IMO a best effort would make life much easier for the overwhelming majority of cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: hardFairly difficult to solvepriority: lowLow priority for the Knurling teamstatus: needs designThis feature needs design work to move forwardtype: enhancementEnhancement or feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions