That depends on the purpose.
Print statements provide debug output, and are included in for example crash logs. The are needed to figure out why something crashed.
If you feel the need to write (like in this example) exception logging to a file, you need to become a better programmer. Exceptions are exactly that, they should ONLY occur when something unexpected happens, and not because (again like in this example) you couldn't be bothered to properly validate your data before using it.
Also note that stdout and stderr are captured and processed depending on the debug level set. Writing to your own file not only bypasses this mechanism, but also causes your log not to show up if this mechanism is overridden centrally, for example to send log data elsewhere.
Note that debug ouput != application logging.
Logging application processing, for example autotimer timer processing details, should be written to an application specific log file, it has no place in debug output, and only floods the output with irrelevant data.
Edited by WanWizard, 20 February 2019 - 13:55.
Currently in use: VU+ Duo 4K (2xFBC S2), VU+ Solo 4K (1xFBC S2), uClan Usytm 4K Ultimate (S2+T2), Octagon SF8008 (S2+T2), Zgemma H9.2H (S2+T2)
Due to my bad health, I will not be very active at times and may be slow to respond. I will not read the forum or PM on a regular basis.
Many answers to your question can be found in our new and improved wiki.