Skip to content

feat(logger): basic logger logic #9

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

Merged
merged 27 commits into from
Mar 14, 2021
Merged

feat(logger): basic logger logic #9

merged 27 commits into from
Mar 14, 2021

Conversation

saragerion
Copy link
Contributor

@saragerion saragerion commented Feb 22, 2021

Issue #, if available:

Description of changes:

This is a PR containing the business logic for the logger, and it's part of this list:

  • CURRENT: create logger logic with basic unit tests and examples
  • TODO: Update test suite with missing unit tests and relevant test cases/scenario
  • TODO: Create docs
  • TODO: CI/CD pipeline for publishing

Usage

See readme file for examples.

Key features

All functionalities/features existing the other loggers are (or should be, unless I missed them) implemented and part of this PR.

The TypeScript logger differs from the others in these features:

1. Decorator functionality is not in this PR.
TypeScript currently only supports Decorators for Classes.
This means that to make decorators work folks need to change their code to make the Lambda handler a method of a class. This is not a common practice of how folks implement the handler logic for the Node.js runtime, as far as I know. Please feel free to add your perspective on this in the review.

2. Possibility to configure the logger settings (options) via constructor or custom configuration service
On top of the already existing configuration for the logger that can be done via environmental variables, developers can optionally bootstrap the logger settings by passing them in the constructor, or relying on a custom configuration service (that could extend the functionality of the existing one, or be of a different kind like AppConfig).

Options for the logger (log level, feature toggles on/off) are set dynamically by checking these "sources", in this specific order:
settings passed in Logger class constructor settings declared in custom configuration service settings declared in default environmental variables service.

3. BYOL: Bring Your Own Log (structure)
This powertool's logger by default prints logs having the same JSON schema as the other tools.
I extended this functionality to optionally allow developers to set their own log JSON schema, if they want to.
The reason behind this choice is that some developers, especially in big organizations, might need to comply with their company's standardized logging RFC and schema implemented company-wide for Lambda, containers, or code running on EC2. This is a necessity when logs are sent to a central logging SaaS vendor and the log key/values need to be indexed.
Another use case could be implementing a JSON schema compatible with the opentelemetry-specification standard.

4. Location field is missing
This is honestly a great feature the other tools have. But currently there is no easy or not-hacky way to get this information in Node.js/Typescript. The closest feature I found is this library here.
Shall we use it?

Checklist

Breaking change checklist

RFC issue #:

  • Migration process documented
  • Implement warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@saragerion saragerion changed the title [IN PROGRESS] feat(logger): basic logger logic feat(logger): basic logger logic Mar 12, 2021
@saragerion saragerion marked this pull request as ready for review March 12, 2021 17:49
@saragerion saragerion added the logger This item relates to the Logger Utility label Mar 12, 2021
@saragerion saragerion added all and removed all labels Mar 13, 2021
@heitorlessa
Copy link
Contributor

This is so awesome to see 🤩🎉

Because it's a big PR, could you update the PR description or Logger.md with examples of usage?

That would be quicker as I'd focus on the UX first, and get acquainted with the project tooling and structure as I go along ;)

Thank you!!!

@saragerion saragerion merged commit 5f867ea into main Mar 14, 2021
@saragerion saragerion deleted the logger-base branch March 14, 2021 12:51
@flochaz flochaz mentioned this pull request Dec 6, 2021
10 tasks
@saragerion saragerion self-assigned this Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logger This item relates to the Logger Utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants