Better query logging in debug mode