Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support/http: allow services to specify the logger used by the logging middleware #2314

Merged
merged 4 commits into from
Feb 24, 2020
Merged

support/http: allow services to specify the logger used by the logging middleware #2314

merged 4 commits into from
Feb 24, 2020

Conversation

leighmcculloch
Copy link
Member

@leighmcculloch leighmcculloch commented Feb 22, 2020

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Allow services to specify the logger used by the logging middleware.

Why

LoggingMiddleware gets the logger from the context using "support/log".Ctx(...). If none is specified in the context the "support/log".DefaultLogger is used. Because the LoggingMiddleware is placed into the chi.Mux in the NewMux and NewAPIMux functions a service using these functions has no opportunity to set a logger on the context because a middleware cannot be inserted earlier. This means by using NewMux and NewAPIMux you are stuck with the default logger.

Why Behind the Why

The reason I'm wanting this is because webauth and recoverysigner are similar to ticker in that they explicitly define all their dependencies and pass them down to the code using them as explicitly as possible. Because of this both of those applications define their own logger. Because we have some code like the LoggingMiddleware that magically pulls the logger out of the context setting it in the context is the only way to fully use a custom logger.

Alternative Implementations

If you look at the commits on this PR I attempted to implement this one way first using functional options. It seems pretty cool 😎 but more complicated that is necessary so I dropped it.

Known limitations

N/A

@leighmcculloch leighmcculloch self-assigned this Feb 22, 2020
@cla-bot cla-bot bot added the cla: yes label Feb 22, 2020
Copy link
Member

@accordeiro accordeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had an offline discussion, left an inline comment to summarize 👇

support/http/mux.go Outdated Show resolved Hide resolved
Copy link
Member

@accordeiro accordeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :)

@leighmcculloch leighmcculloch merged commit c16941a into stellar:master Feb 24, 2020
@leighmcculloch leighmcculloch deleted the allow-supply-logger branch February 24, 2020 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants