Factor out log handling.