Rewrite logging code in main.cpp.

Created LogWriter class with all log-specific code.
Removed unnessesary stream.flush() calls and minimized
  time under locked mutex.
Expected no behavior change.

In future LogWriter class can be easily moved into separate *.hpp\*.cpp files.
Then it can be tested with unit-tests.