-
Notifications
You must be signed in to change notification settings - Fork 54
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
Leverage cargo features to selectively enable logging levels #44
Conversation
Hi @rafalh, friendly ping in case you missed this. 😃 |
Hello @kevinaboos . Sorry for long delay. |
Hi @rafalh , thanks for the reply and the great questions!
Yes, the motivation for me introducing this changeset is to get around this problem, which is an issue stemming from how cargo performs Notably, there are a few alternatives to this design. One easy choice is to make the [dependencies.fatfs]
version = "..."
default-features = false
features = [ ..., "log" ] That works and is very simple, but it's also quite coarse-grained, as I mentioned in my original post. In the event of something going wrong, I'd personally love to see error and warning-level logs printed by the
There are quite a few, but none are quite as flexible as what I've presented in this PR. I think one of the core issues is that most other third-party crates I've come across don't use as many log statements as For example, the smoltcp crate does something similar but with its own Let me know what you think. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add info about new features in README.md
and in CHANGELOG.md
Isn't the point of the log crate that the logging backend can filter log messages based on the crate that emitted them? Why don't you just configure your log backend to ignore fatfs' messages? |
Sorry for the delay in my response! @rafalh I will add some details shortly when I get the chance. @Xiretza, yes, you're correct that the logging backend could be configured to skip arbitrary messages. However, that filtering behavior would occur at runtime and would still result in log calls being emitted in the binary, which would cause unnecessary overhead. In contrast, the changes I've proposed here allows one to disable logging levels statically at compile time, which is preferable IMO. |
@rafalh I have made the requested changes, and also merged in the latest changes from the master branch to ensure no conflicts arose. Let me know if you'd like to see any other changes. Thanks again for this excellent crate! |
Thanks for your contribution! |
Hi @rafalh, thanks for your excellent work creating this crate!
Background
I've been experimenting with adding support for FAT32 filesystems in Theseus, my pure-Rust OS, and have successfully used this crate to do so. However, my OS uses the
log
crate copiously, with logging statements being emitted by a large variety of different sources; all of the other crates allow toggling of log statements for convenience in debugging.I thought about just taking the simple approach of adding one coarse-grained feature that disables all logging, but then I figured it'd be nice to have warn-level or error-level log statements continue to be emitted by
fatfs
while bypassing the verbose trace-level logging that is currently emitted.New feature
Thus, this PR adds support for selectively enabling logging levels using cargo features. I tried a few different approaches and found that this was the best -- it effectively provides overridden versions of the key macros from the
log
crate that are used transparently across the rest of thefatfs
crate. The cargo features are inspired by those exposed by thelog
crate itself.The default features have been augmented to enable all log statements from the
trace
level and up, which corresponds to the current default behavior of the crate.Kindly let me know if you'd like me to make any changes, I'm happy to do so.