Improve query logging