Backport PR "Log exceptions" to 2.3

These commits have already been merged into master.