Cover All Exceptions: Python Error Logging

  • Context: Python 
  • Thread starter Thread starter cpscdave
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on implementing comprehensive error logging in Python for a headless server application. The user seeks a method to handle all exceptions and maintain server uptime by logging errors. A suggested approach involves using a try-except-finally block to catch specific exceptions like RuntimeError, TypeError, and NameError, while also considering an infinite loop to restart the server and log errors automatically. This method ensures that the application continues running despite encountering exceptions.

PREREQUISITES
  • Understanding of Python exception handling
  • Familiarity with try-except-finally constructs in Python
  • Knowledge of logging in Python using the logging module
  • Basic concepts of server deployment and management
NEXT STEPS
  • Explore Python's logging module for advanced logging techniques
  • Learn about handling multiple exceptions in Python
  • Research strategies for implementing fault tolerance in server applications
  • Investigate the use of infinite loops for process management in Python
USEFUL FOR

Python developers, system administrators, and anyone involved in deploying and maintaining server applications who need to ensure robust error handling and logging mechanisms.

cpscdave
Messages
402
Reaction score
120
I feel a bit dirty asking this..
But I've written a fairly large program that is going to be deployed in a few weeks. Its a headless server. I've done error checking throughout the code where I am aware of it, but I'm worried about the things I have missed.

Is there a way in python I can get it to continue on all exceptions? Perhaps write out an error log as well?? I highly doubt there is but thought I'd check :)
 
Technology news on Phys.org
Can you predict which exceptions are likely to be thrown? If so, maybe something like this is feasible:
Python:
try:
   <some code that might throw>
except (RuntimeError, TypeError, NameError):
   <handle error>
finally:
   <clean up>
 
  • Like
Likes   Reactions: cpscdave
You could double down on that slightly dirty feeling and write a program with an infinite loop that launches your server, captures stderr and diverts it to a logfile. In other words, an automatic log-it-and-reboot.
 
  • Like
Likes   Reactions: cpscdave
Ibix said:
You could double down on that slightly dirty feeling and write a program with an infinite loop that launches your server, captures stderr and diverts it to a logfile. In other words, an automatic log-it-and-reboot.

Haha that might actually not be a bad idea.
This is the classic case of I want a few weeks to test, and I have a few days :P

I'm going to add some GOTO's just to make my fall from grace complete.
And who needs comments in the code??
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
Replies
3
Views
1K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 43 ·
2
Replies
43
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
15K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
Replies
1
Views
2K