fern icon indicating copy to clipboard operation
fern copied to clipboard

Recipes for CLI logging with fern

Open daboross opened this issue 6 years ago • 4 comments

Fern is currently nice to configure, but might be a bit verbose for someone just wanting a CLI logger. It would be nice if we had some easy to use recipes for common use cases.

While this would be beneficial, I don't think adding additional duplicated functionality to fern itself would be a good idea. Instead, a crate fern-recipes could be created, containing a bunch of helper functions, each with two variations: returning std::io::Result<fern::Logger>, and returning Result<(), fern::InitError>.

If anyone has a better idea on how to include these recipes, or wants to start making some, feel free to chime in below.

daboross avatar Sep 04 '17 07:09 daboross

I'm imagining at least 3 recipes to start with: [date time][module][level], [module][level] and [level] module:. All these would output to stdout only, and would include colors if supported by the OS.

We could also include one for outputting [module][level] to console, and [date time][module][level] to a provided log file.

All of the formatters should also be usable independently, so that one could do fern::Dispatch::new().format(fern_recipes::module_and_level_format).apply().

daboross avatar Sep 04 '17 07:09 daboross

If anyone's reading this and/or subscribed to the issue: any thoughts on fern::recipes under a enabled-by-default "recipes" flag vs. fern-recipes crate?

I'm currently leaning towards fern-recipes so it can depend on chrono and include time in all of them by default, but an inline module would be much more discoverable. I'm also partial to having fern::recipes::module_and_level().init() as a nice easy example of the library.

daboross avatar Jun 17 '18 06:06 daboross

I like having everything feature-gated by chrono and color individually.

piegamesde avatar Jul 09 '21 00:07 piegamesde

Agreed! If we go with the recipes name for this feature, the base ones could be gated under the recipes feature, and then time-based under both recipes and chrono, for example. I definitely want to keep all extra dependencies under features like they are now.

daboross avatar Jul 09 '21 00:07 daboross