Fixed SQL logging