Writes messages to logfile instead of stdout if debug is enabled.