Added custom query logging in exceptions