Added log path validation and optional creation of the log directory if it doesn't exist.