DRY up log patching logic

Move the shared logic into a Helpers method so that there is no
code duplication