Log messages instead of using print

Fix bug 2928