(Bug 4876) Stop the job if it fails while setting up log file

Moves initialiaziation of $logfile out of the $log sub, so that if it fails,
and we return $temp_fail->(...), it actually cuts the import short.

Otherwise, the import job just continues, just with no logging, and the user
gets both a "succeeded" and "failed" message in their inbox. Confusing!