Move logging into raw query functions.