added query logging