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

Refactor Hapi-pino logger to clean things up #49

Merged
merged 1 commit into from
Dec 12, 2022

Conversation

Cruikshanks
Copy link
Member

The first tweak is around config. We were pulling it into our main app/server.js and HapiPinoIgnoreRequestService. This meant we also needed to stub the config to get tests working for the HapiPinoIgnoreRequestService. By moving the config into the plugin we can use it where it's needed, and ensure it gets passed through as an arg. This means LogConfig is now only referenced in one place and we can remove the stubbing in our HapiPinoIgnoreRequestService tests because we're passing the critical option through.

The second was a mix of conventions. We were using a separate service to contain the logic of whether a request should be logged but a function in the plugin to cover logging in tests. By moving the logging in tests logic to a service we get consistency and we can write some unit tests to cover it.

First tweak is around config. We were pulling it into our main `app/server.js` and `HapiPinoIgnoreRequestService`. This meant we also needed to stub the config to get tests working for the `HapiPinoIgnoreRequestService`. By moving the config into the plugin we can use it where its needed, and ensure it gets passed through as an arg. This means `LogConfig` is now only referenced in one place and we can remove the stubbing in our `HapiPinoIgnoreRequestService` tests because we're passing the critical option through.

The second was a mix of conventions. We were using a separate service to contain the logic of whether a request should be logged but a function in the plugin to covere logging in tests. By moving the logging in tests logic to a service we get consistency _and_ we can write some unit tests to cover it.
@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Dec 9, 2022
@Cruikshanks Cruikshanks self-assigned this Dec 9, 2022
@Cruikshanks Cruikshanks marked this pull request as ready for review December 9, 2022 17:49
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

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

@Cruikshanks Cruikshanks merged commit 11632f2 into main Dec 12, 2022
@Cruikshanks Cruikshanks deleted the refactor-hapi-pino-ignore-request-service branch December 12, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants