Fix debug query logging