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(logging): topicLogger for headers #5586

Closed
wants to merge 2 commits into from

Conversation

tomcat323
Copy link
Contributor

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 a variable of the getLogger() function.
  2. Define a set of topics to be used in message headers, covering all services and modules.

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

@tomcat323 tomcat323 changed the title Refactor(logging): Implemented topic headers refactor(logging): Implemented topic headers Sep 13, 2024
@tomcat323 tomcat323 changed the title refactor(logging): Implemented topic headers refactor(logging): topicLogger for headers Sep 13, 2024
@@ -5,25 +5,20 @@

import * as vscode from 'vscode'

/** define log topics */
type LogTopic = 'Unknown' | 'Test'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type LogTopic = 'Unknown' | 'Test'
type LogTopic = 'unknown' | 'test'

* Used as a wrapper around the logger interface for appending messages
* Also more compatible with future change
*/
abstract class baseLogger implements Logger {
Copy link
Contributor

@justinmk3 justinmk3 Sep 13, 2024

Choose a reason for hiding this comment

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

WinstonToolkitLogger is referenced in only a few isolated places--it's already "encapsulated". The logger interface is essentially getLogger(), and already abstracts logging for the codebase.

Our base logger is winstonToolkitLogger.ts, but it has a misleading name. At present it happens to use winston as the "backend", but that can always be changed in the future without any accruing costs / tech debt. Whereas in the meantime, adding extra indirection (in the form of 2 new classes, TopicLogger and baseLogger) is a permanent cost that may never pay off.

To summarize, the near-term steps we can take are:

  • rename winstonToolkitLogger.ts to toolkitLogger.ts.
  • add addTopicToMessage to it.

In the future if we need other logger implementations, those can be added at near-zero cost because callers are already using the getLogger() abstraction.

Copy link
Contributor

@nkomonen-amazon nkomonen-amazon Sep 13, 2024

Choose a reason for hiding this comment

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

It looks like this Base class can apply to the existing loggers NullLogger, ConsoleLogger, and the WinstonLogger. Would it make sense to have them all the implement this abstract class? This will allow us to drop each of their duplicated info(), debug(),... methods

Winston logger would still have the addTopicToMessage() method as Justin suggested

Copy link
Contributor

Choose a reason for hiding this comment

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

sure that makes sense

@tomcat323 tomcat323 closed this Sep 16, 2024
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.

3 participants