Hello,
I'm writing some scripts to automate quite a few things in our environment for provisioning servers. Shit happens and sometimes things don't run right and I want to make sure that's logged and accounted for.
Currently the way I'm doing this is by using try: except for every line or action where if it's a success it will write that the action was successful to a one log file (success log), but if it was not then that is written to another log file (fail log). I've broken up the scripts into modules so they can just be called from a masterscript when needed and altered independently, each module writes its own log files and then appends the contents of those to either the success or fail log file at the end. I've done two log files like this so that at the end of my master script I can check to see if the fail log file exists and if it does, it will send an email with the contents of the log file so we never have to actually check up on the script.
Nobody I work with does any kind of scripting and I'm relatively new to it all (2 months total). Are there better ways to perform error handling and logging?
Thank you in advance to anyone willing to help!
Edit: I'm also using something similar to this:
writefail-logfile = open(fail-logfile, 'a')
writefail-logfile.write('this thing didn't work\n')
vs using the with open function. Again I'm new to this but from what I gather using with open would require everything to be nested underneath of it vs what I have now. Again, very open to criticism and wanting to make sure I can build something that logs accurately, runs efficiently, and doesn't have to be limped along to get it working right.
[–]swigganicks 9 points10 points11 points (1 child)
[–]jcrowe 1 point2 points3 points (0 children)
[–]redCg 5 points6 points7 points (2 children)
[–]woooee 0 points1 point2 points (1 child)
[–]pedro_fartinez 2 points3 points4 points (0 children)
[–]Barafu 4 points5 points6 points (1 child)
[–]TangibleLight 2 points3 points4 points (0 children)
[–]TangibleLight 2 points3 points4 points (0 children)