Backport better log handling from elections14. Closes #419.