added automatic mode (previously available too)
log to stdout when running in foreground
added debugging flag