As an organization, you may need to run Python scripts on a scheduled basis, such as through Windows Task Scheduler. However, determining whether a Python script executed successfully or encountered an error can be challenging. Monitoring the results can become quite cumbersome, especially when scripts are running frequently. Even with log file generation, consistently checking for errors can be inconvenient. The attached Logger.py file is designed to create log files and send an email notification in the event of an error. For a demonstration of how this can be utilized, please refer to the video below.
Logging is pretty important. I would say, that a good practice I've had one of my teams use is to log to a shared network folder, so all logs are in one place.
Another thing you can do is to leverage email, and send a message when key failures happen.
Thank you very much for sharing this. We've implemented something similar with scheduled task scripts so it's nice to see we are on the same track. I would like to add that I noticed there are occasions where Esri seems to utilize the logging module for some things because our log file was getting extra info from those tools. We created custom log levels so as not to interfere with Esri logging. We also put the contents of the log file right into the body of the email rather than attach the file.