Backport logging fixes from release 3.0

This should help fix #824.