Refactor log outputting mechanism.