Use log level for image writing progress messages.#1448
Conversation
jakeforster
commented
May 31, 2026
- Core/ComponentBaseClasses/elxResamplerBase.hxx (WriteResultImage): Use log::info instead of log::to_stdout.
- Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx (WritePyramidImage): Likewise.
- Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx (WritePyramidImage): Likewise.
* Core/ComponentBaseClasses/elxResamplerBase.hxx (WriteResultImage): Use log::info instead of log::to_stdout. * Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx (WritePyramidImage): Likewise. * Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx (WritePyramidImage): Likewise.
| if (showProgress) | ||
| { | ||
| log::to_stdout(" Writing image ..."); | ||
| log::info(" Writing image ..."); |
There was a problem hiding this comment.
Thank you for your pull request, @jakeforster However, I'm not sure. These three log::to_stdout(" Writing image ...") calls were really there to ensure that the messages are only printed to the console (not the log file). They are actually the only three use cases of log::to_stdout.
The print statement in ResamplerBase::WriteResultImage was originally added by commit 517406d, July 25, 2008 (before I got involved with elastix):
xl::xout["coutonly"] << "\n Writing image ..." << std::endl;"coutonly" suggests that it should not go to the log file.
However, there could certainly be room for improvement. @jakeforster What problem exactly do you want to solve with your pull request?
There was a problem hiding this comment.
Hi Niels, the problem is that these messages do not respect the log level. If the user sets the log level to warn or error, it is presumably because they do not want progress messages like these to be shown.
There was a problem hiding this comment.
@jakeforster Thanks, I see your point.
Your current pull request has the "side effect" that it places those " Writing image ..." messages in the log file, whereas I think they were only meant to inform an interactive user of the progress, while elastix is running.
Instead, as a compromise, we could replace log::to_stdout with a new function, log::info_to_stdout, which would only use stdout, and only when the log level is info (so the most verbose level). What do you think?
There was a problem hiding this comment.
Sounds good to me. Thanks for your time.
There was a problem hiding this comment.
There's another case we may then need to reconsider. ProgressCommand::PrintProgress unconditionally prints the progress percentage to std::cout as well. I'll have another look later this week. Please remind me, if necessary 😃
`log::info_to_stdout(message)` respects the log level: it only prints the message when the log level is `info`. Inspired by pull request #1448 "Use log level for image writing progress messages", jakeforster, May 31, 2026.
Of course, my pull request was very much inspired by yours, so thanks very much @jakeforster ! 👍 |