Fix progress logs redirected to file
For more than a decade, OTB has generated output log files like this :
Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 0% [ ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 3% [* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 4% [** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 6% [*** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 9% [**** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 10% [***** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 12% [****** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 14% [******* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 17% [******** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 18% [********* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 20% [********** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 23% [*********** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 25% [************ ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 26% [************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 28% [************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 31% [*************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 32% [**************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 34% [***************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 37% [****************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 39% [******************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 40% [******************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 42% [********************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 45% [********************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 46% [*********************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 48% [************************ ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 50% [************************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 53% [************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 54% [*************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 56% [**************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 59% [***************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 60% [****************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 62% [******************************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 64% [******************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 67% [********************************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 68% [********************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 70% [*********************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 73% [************************************ ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 75% [************************************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 76% [************************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 78% [*************************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 81% [**************************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 82% [***************************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 84% [****************************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 87% [******************************************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 89% [******************************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 90% [********************************************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 92% [********************************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 95% [*********************************************** ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 96% [************************************************ ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 98% [************************************************* ]Writing /home/otbval/Dashboard/nightly/OTB-Release/build/Testing/Temporary/apTvLSMS2_Segmentation_NoSmall.tif...: 100% [**************************************************] (0s)
This type of progress logging only works on an interactive terminal, not when the logs are redirected to a file. I have been wondering how this should be adressed, but comparing with other command line tools, the answer can be simple: we only print progress when the output stream is interactive. I have looked at git source code, they use the C function isatty(int fd)
to detect if output stream fd
(usually 1 or 2) is a terminal. On Windows they use specific windows API to do the same thing.
We should do something similar in OTB. The behaviour in non-tty cases could also be smarter, for instance:
- the progress logger prints its messages in a memory buffer, overriding any previous content
- when the progress reaches 100%, the buffer is printed to
cout
and cleared (so in the log file, we have only 1 line saying that the process completed) - when an exception happens, the buffer is printed to
cout
(so when a crash happen, we know where was the progress at that time)