Improved log event and error handling