Transferred code from mailgun/gotools-log repo.