Add query logging.

Three new options added
- log_queries, if true log queries, defaults to false
- log_queries_filename, the file where queries are logged, defaults to `queries.log`
- log_queries_threshold, only log queries that run slower than threshold (in milliseconds)
  defaults to 0, i.e. log all queries.
@davidegrohmann I am not sure that close is always called on the iterator, but maybe you're right. As I see it endSuccess should always be idempotent but maybe I need to be more clear about this.