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.
Use std::cerr instead of std::cout for any log message.
Merge pull request #2 from dreamer-dead/logwriter

Rewrite logging code in main.cpp.