aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.51k stars 436 forks source link

feat(logging): topic header for logs #5610

Closed tomcat323 closed 1 month ago

tomcat323 commented 1 month ago

Problem

Log message can appear in output channels(such as Amazon Q Logs as shown), IDE Debug console, or write to pre-defined log file destinations. They come from all parts of our services and can amount to large and lengthy chunks quickly.

We don’t have a reliable way to identify log messages from various services and modules of our product. Some messages might have headers while others don’t, and the existing headers are hard-coded on a message by message basis, with no checks for consistency.

  1. It’s difficult to locate and trace unidentified log messages when the size of logs grow quickly.
  2. Without regulation, the hard-coded custom headers can lead to legacy issues down-the-road and inconsistencies within the codebase.

Solution

  1. Make message topic identifiers an input variable of the getLogger() function.
  2. Append the topic at the front of each message, for example: getLogger('S3').error('Something went wrong') Would print: S3: Something went wrong
  3. Define a set of topics to be used in message headers, covering all services and modules.

Implementation notes:

  1. The WinstonToolkitLogger is renamed to ToolkitLogger to avoid confusion, since its our own logger not winston's. The log topic feature is added here.
  2. A baseLogger abstract class is created to make the existing NullLogger, ConsoleLogger, and ToolkitLogger cleaner and their responsibilities more obvious and compact.
  3. Currently the topics are optional, and the values are just Test and Unknown, this will be expanded during migration of existing logger calls.

License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

github-actions[bot] commented 1 month ago

This pull request modifies a feature or fixes a bug, but it does not include a changelog entry. All pull requests that introduce new features or bug fixes must have a corresponding changelog item describing the changes.

github-actions[bot] commented 1 month ago

This pull request implements a feature or fix, so it must include a changelog entry. See CONTRIBUTING.md#changelog for instructions.

tomcat323 commented 1 month ago

For context this implementation is resulted from a discussion in a previous closed PR:

Screenshot 2024-09-18 at 11 17 43 AM
tomcat323 commented 1 month ago

/retryBuilds