Added logging. Use --loglevel DEBUG to turn it on. Outputs to log.txt