Fix logging on immediate exit on start

If elasticsearch was started in the foreground an immediate exit on startup
led to logging in the logfile, where as when starting in the background,
an immediate exit logged to stdout.

Closes #4805