Add error catching to logging