Logging for code used as lib and bin
⚓ Rust 📅 2025-12-07 👤 surdeus 👁️ 1Hello everyone,
I have written some code (which performs bash operations) that can be executed via a CLI bin (to directly use the features of my code) and can also be used as a library.
When my code is executed via the CLI interface, My logs are printed as INFO. But when my code is executed via the library, it might be more appropriate (depending on the user, but according to my use) for these same logs to be DEBUG (and with different formatting).
I imagine I can create a different formatter depending on the use of the bin/lib (with features?). And encapsulate logging behind mechanisms that change INFO/DEBUG based on a parameter.
But I guess this is a common case. And maybe there is a pattern for this?
3 posts - 3 participants
🏷️ Rust_feed