Added a bunch of error checking and fixed some incorrect error handling.

Modified the init code to check for arguments that beging with --log
immediately so that log messages generated during initialization are
properly handled.

Added a reset to the logging code right after argument processing in case
the setup has changed.