Cover All Exceptions: Python Error Logging

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

Discussion Overview

The discussion revolves around strategies for error logging in a Python program intended for deployment on a headless server. Participants explore methods to handle exceptions and ensure that the program continues running despite errors, while also capturing logs for troubleshooting.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses concern about missing exceptions in their code and inquires about a way to continue execution despite errors while logging them.
  • Another participant suggests predicting potential exceptions and using a try-except block to handle specific errors, followed by a cleanup process.
  • A different approach is proposed, involving an infinite loop that restarts the server and captures standard error output to a log file, described as an "automatic log-it-and-reboot" solution.
  • One participant humorously acknowledges the idea of using an infinite loop and mentions adding GOTO statements, reflecting a lighthearted attitude towards the coding process under time constraints.

Areas of Agreement / Disagreement

Participants present multiple approaches to error handling and logging, with no consensus on a single solution. The discussion remains open-ended, exploring various strategies without resolving which is the best method.

Contextual Notes

Participants do not provide specific details on the limitations of their proposed methods, such as potential pitfalls of using infinite loops or the implications of broad exception handling.

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
4K
  • · 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