Move logger up to be available sooner.
Only ensure server if we are running the app.

This code reorder avoids to get an error message if we run some code
when the only thing we want is to get the version.

Closes #3914.
Merge remote-tracking branch 'ivan-github/bug/3914_unhandled-error-on-version-flag' into develop