Crate is logging to stderr and not to my log file

My app is using log4rs (and log) for logging and I've just added the clap crate to handle command line args. Both are working, but the clap crate is doing its own logging to stderr and not to my logfile or my console logger.

What do i need to do to get an external crate to use my application's logger?

Generally, the library will need to provide some sort of hook so you can tell it to write output to your application's logger, so you'll need to look through its API docs or issue tracker to find that hook.

1 Like

When clap prints to stdout and stderr (and currently you can't change that, I think. I believe the the logic behind clap's logging can be found in this file: clap/fmt.rs at master · clap-rs/clap · GitHub), maybe---I don't know your full setup---you could also log to stdout and stderr and pipe the output into your logfile? I.e. call something like this in your console (bash syntax):

your-program --your-args 2>&1 > log-file.txt
1 Like

Thanks for the response @Michael-F-Bryan & @jofas !
Based on your input, I cloned the repo and started digging into the source code-- beginning in clap/fmt.rs and ending up in clap/macros.rs-- only to realize that clap was defining its own debug!() macro when the debug feature is added. :cry:
So, yeah. This was entirely my bad. I must have inadvertently copy/pasted that feature in when i was adding the clap features that I needed.
Thank you both for the help/support !! I'm really loving learning rust, and I'm discovering that the community is just as awesome as the compiler :smiley:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.