Better error handling for logging.