First attempt at making logging work both for daemon and foreground modes.