Log messages instead of using print

Also cleanup to fix indentation

Fix bug 2928