Skip to content

perf: check the log level before building log arguments - #286

Open
chaikivskyi wants to merge 1 commit into
roadrunner-server:masterfrom
chaikivskyi:perf/log-level-guard-master
Open

chaikivskyi wants to merge 1 commit into
roadrunner-server:masterfrom
chaikivskyi:perf/log-level-guard-master

Conversation

@chaikivskyi

Copy link
Copy Markdown

Reason for This PR

writeLog built the full argument list for every request before handing it to slog, so the work was performed even when the configured log level discarded the record. On a deployment running logs.level: warn or error - where no access log is ever emitted - each request still paid for r.URL.String(), start.Format(...), the stripCRLF calls, etc.

Description of Changes

writeLog now returns early when l.log.Enabled(context.Background(), slog.LevelInfo) is false, before any argument is built.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Signed-off-by: Petro Chaikivskyi <petro.chaikivskyi@credentiable.com>
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.

1 participant