I choose to log deliberately as I go, as this means the log data is meaningful:
- Depending on logging framework you can add level/severity/category information so that the log data can be filtered
- You can make sure that the right level of information is present, not too much, not too little
- You know when writing the code which the most important things are, and can therefore ensure they are logged
Using some form of code injection, profiling or tracing tool to generate logs would most likely generate verbose, less useful logs that would be harder to dive into. They may be useful as a debugging aid, however.