Skip to content

fix(logger): display correct log level in cloudwatch #386

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 2 commits into from
Jan 3, 2022

Conversation

saragerion
Copy link
Contributor

@saragerion saragerion commented Jan 3, 2022

Description of your changes

Fixes: #378

How to verify this change

  • Unit tests

Related issues, RFCs

#378

PR status

Is this ready for review?: YES
Is it a breaking change?: NO

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published in downstream module
  • The PR title follows the conventional commit semantics

Breaking change checklist

N/A


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

return;
}
this.printLog(this.createAndPopulateLogItem('DEBUG', input, extraInput));
this.processLogItem('DEBUG', input, extraInput);
Copy link
Contributor Author

@saragerion saragerion Jan 3, 2022

Choose a reason for hiding this comment

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

Housekeeping: removed unnecessary code duplication

log.prepareForPrint();

const consoleMethod = logLevel.toLowerCase() as keyof ClassThatLogs;

console[consoleMethod](JSON.stringify(log.getAttributes(), this.removeCircularDependencies()));
Copy link
Contributor Author

@saragerion saragerion Jan 3, 2022

Choose a reason for hiding this comment

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

Here I:

  • Removed the JSON parse step so that the log items will be displayed more nicely (green coloured values) in cloudwatch (see image)
  • Moved the circular reference logic to its own method so make it easier to read, adding relevant jsdocs documentation and separate responsibilities

Screenshot 2022-01-03 at 18 34 29

@saragerion saragerion self-assigned this Jan 3, 2022
@saragerion saragerion added bug Something isn't working logger This item relates to the Logger Utility labels Jan 3, 2022
@saragerion saragerion added this to the beta-release milestone Jan 3, 2022
@saragerion saragerion linked an issue Jan 3, 2022 that may be closed by this pull request
@saragerion saragerion marked this pull request as ready for review January 3, 2022 17:40
@saragerion saragerion changed the title fix(logger): correct log level in cloudwatch fix(logger): display correct log level in cloudwatch Jan 3, 2022
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for making this!

* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
* @private
*/
private removeCircularDependencies(): (key: string, value: LogAttributes) => void {
Copy link
Contributor

Choose a reason for hiding this comment

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

💯 This is much easier to read and understand.

@dreamorosi dreamorosi merged commit 23ee7f4 into main Jan 3, 2022
@dreamorosi dreamorosi deleted the fix/logger-logging-level branch January 3, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logger This item relates to the Logger Utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: incorrect log level in CloudWatch
4 participants