Changed print statements to use logging

Also added logging where we see exceptions.