It really depends on your requirements:
If all you want is to print a simple string like in your example, skipping a function call may be fine.
But what happens if you want to add metadata, like a timestamp, or a tag?
Wrapping your logging code in a function gives you the following advantages:
- You can format the log output without rewriting the formatting code
- You can easily have more than one type of loggin and choose which is active (error, warning, debug, info)
- You can easily change out print for something else in the future if the need arises, like writing to file, or to
stderr
instead of stdout
- Your code will be more clear, since it will be obvious what is log and what is output
- You will have to type less
The example you provided is only good for trivial code and trivial debugging, but since you want to control debugging with a variable, clearly you have more than a trivial script.
So, if you still don't want to use proper logging library for some reason, at least, do wrap your logging code in a proper function as otherwise you are likely to reduce the readability and maintainability of your code.