Added log level error handling and logging.