Add new logging code.
Convert existing code to use logger.h.
Write pid file even in foreground mode.