media-io / yaserde

Yet Another Serializer/Deserializer
MIT License
175 stars 57 forks source link

Use "yaserde_derive" as the log target for generated logging calls #120

Closed Felerius closed 2 years ago

Felerius commented 3 years ago

This fixes #16 by allowing users to filter out the log messages. For example,

RUST_LOG="debug,yaserde_derive=off" cargo test -- --nocapture

works as expected now. After upgrading to env_logger 0.9, it even shows yaserde_derive instead of the module path in the logging messages (due to env-logger-rs/env_logger#209):

...
[2021-07-24T10:24:33Z DEBUG yaserde_derive] Struct Data @ 0: start to parse "data"
...

To avoid specifying target: "yaserde_derive" in every logging call, I created custom __derive_debug and __derive_trace macros in the main crate. However, they could just as well be inlined. Lastly, I hid the re-exported xml and log crates from docs and prefixed them with __ to indicate that they're not considered public api.

Felerius commented 3 years ago

I just realized that renaming the xml and log re-exports is technically a breaking change since they might be used outside of yaserde_derive. If you don't want that then, they could instead be made doc(hidden) without renaming them.