Now writes to a log file when in debug mode.