checking exit code and logging output on success