added ability to log to file by setting logfile in config; updated basesql to call .save() for each batch when fetching in batches