In the Python docs on logging it says "the best tool for the task" of "Display[ing] console output for ordinary usage of a command line script or program" is to use the print()
function.
I don't understand why. What would be the reasoning behind that?
I want to use logging systematically in my project, which is a command line tool with some standard output to the console. All standard output normally generated by print()
should also go to the log file.
For my root logger I use both a StreamHandler for console output and a FileHandler to generate a log file. If I want to follow the recommendation I have to either duplicate every print-statement with an identical logging-statement or find a way to redirect the output from print()
as suggested in this question. The accepted answer there was to replace the print function by writing print = log.info
, which effectively amounts to using logging for ordinary console output after all.