-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add log messages to nitrocli #177
Comments
Yeah, I was also thinking about that. I agree it would be nice to have more visibility into it. I actually have had pretty good experience with So probably just some simple logging backend that we can convince to emit to stderr as I think
Do you mean |
I’d start off with
Sorry, that was a typo and supposed to say nitrocli. As long as nitrokey-rs is a rather thin wrapper around libnitrokey, I don’t think it needs separate logging. |
What is a bit of an issue is that we can’t easily share multiple mutable references to our |
All |
Yes, libnitrokey goes to |
👍 |
That would be nice, but it would require some refactoring because the logger has to take ownership of the writer. So I think this could not be part of |
I suppose we'd just need to embed an |
I’ve started looking into the implementation. Some thoughts:
Some pseudo-code as an example for the different log levels: fn connect(model: Model) -> Result<Device, Error> {
log::debug!("Trying to connect to a Nitrokey with model = {}", model);
let devices = nitrokey::list_devices()?;
log::trace!("{} Nitrokey devices found:", devices.len());
for device in devices {
log::trace!("- {} at {}", device.model, device.usb_path);
}
let devices = devices.iter().filter(|d| d.model == model).collect();
if devices.is_empty() {
log::error!("No Nitrokey device with model {} found", model);
anyhow::bail!("No Nitrokey device with model {} found", model);
} else if devices.len() > 1 {
log::error!("More than one Nitrokey device with model {} found", model);
anyhow::bail!("More than one Nitrokey device with model {} found", model);
}
match device.connect() {
Ok(device) => {
log::info!("Connected to Nitrokey device at {}", device.usb_path);
Ok(device)
}
Err(err) => {
log::error!("Failed to connect to Nitrokey device: {}", err);
Err(err)
}
}
} |
Thanks for looking into this topic!
Makes sense. Yeah, to cut down on duplication we should definitely consider piggy backing on the existing
Given what you suggest, I think it should be off. Otherwise whenever an error is emitted won't any error appear twice (because we don't suppress errors anywhere from what I recall)?
Yeah, I think that makes sense, although perhaps an environment variable would be better: this seems to be fairly developer centric and then it would not show up and cause confusion with
I suppose just redirecting output from the shell falls short in some cases or why do we need this option? |
Two aspects: We can’t separate “regular” error messages and log messages. If we redirect stderr, we don’t see the error messages either. And The use case I have in mind for this is pre-emptive logging, for example for errors that are hard to reproduce. The user could set |
Okay, that's what I thought, thanks. 👍 |
Currently, we only have the log messages generated by libnitrokey which can make it difficult to track down issues with nitrocli itself. I suggest to add log messages to nitrokey (especially regarding device and connection handling and PIN caching) to make it easier to debug such issues. The log level should be set according to the
--verbose
option.The text was updated successfully, but these errors were encountered: