Should I use logging module or python's debugger?


Should I use logging module or python's debugger?



I have a question. In which cases should I use python's debugger instead of logging module. I undestand that both are debugging tools, but I don't know how to exactly use them - if it is better to primary debug with logging module or with python's debugger.





Logging isn't only for debugging, it's for retroactively analysing what your program was doing, even hours or weeks after the fact. That's quite different from stepping through an algorithm in a debugger.
– deceze
2 days ago





Logging is not a debugging tool. It is for monitoring and should be done continuously. With the appropriate log level of cause.
– Klaus D.
2 days ago




1 Answer
1



Debugging and logging in an application are two different things.



You should use the debugger when developing an application and resolving bugs (using breakpoints to see the state of the app, executing code step by step).



Logging should be used throughout the app to see what the app is doing (if an error occured catching an exception and logging it, etc.). This helps you when you are not debugging it and you solved most of the bugs, but errors can always occur. When they do you can look at the logs and see the exceptions and behaviour of the app at the time of the crash.





Perfect! Thank you for your explanation. Now I fully understand. I have 1 more question. What's the difference between pdb module and when I use e.g. PyCharm debugger?
– QClodd
2 days ago





No problem :) I think the functionality of the PyCharm one is bigger, but in the core they are the same. I don't know the more in depth differences.
– Andrej Hafner
2 days ago






Okay, thank you for everything. Have a nice day :)
– QClodd
2 days ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV