-
Notifications
You must be signed in to change notification settings - Fork 12
feat: allow configs to take in user provided logger instances for client logging behavior #236
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any*/ | ||
| import { Logger, LogLevel } from '../types/logger'; | ||
|
|
||
| /** | ||
| * Internal logger class that wraps a Logger implementation and handles log level filtering. | ||
| * This class provides a centralized logging mechanism for the Experiment client. | ||
| * @category Logging | ||
| */ | ||
| export class AmpLogger implements Logger { | ||
| private logger: Logger; | ||
| private logLevel: LogLevel; | ||
|
|
||
| /** | ||
| * Creates a new AmpLogger instance | ||
| * @param logger The underlying logger implementation to use | ||
| * @param logLevel The minimum log level to output. Messages below this level will be ignored. | ||
| */ | ||
| constructor(logger: Logger, logLevel: LogLevel = LogLevel.Error) { | ||
| this.logger = logger; | ||
| this.logLevel = logLevel; | ||
| } | ||
|
|
||
| /** | ||
| * Log an error message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| error(message?: any, ...optionalParams: any[]): void { | ||
| if (this.logLevel >= LogLevel.Error) { | ||
| this.logger.error(message, ...optionalParams); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Log a warning message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| warn(message?: any, ...optionalParams: any[]): void { | ||
| if (this.logLevel >= LogLevel.Warn) { | ||
| this.logger.warn(message, ...optionalParams); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Log an informational message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| info(message?: any, ...optionalParams: any[]): void { | ||
| if (this.logLevel >= LogLevel.Info) { | ||
| this.logger.info(message, ...optionalParams); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Log a debug message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| debug(message?: any, ...optionalParams: any[]): void { | ||
| if (this.logLevel >= LogLevel.Debug) { | ||
| this.logger.debug(message, ...optionalParams); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Log a verbose message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| verbose(message?: any, ...optionalParams: any[]): void { | ||
| if (this.logLevel >= LogLevel.Verbose) { | ||
| this.logger.verbose(message, ...optionalParams); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* eslint-disable no-console,@typescript-eslint/no-explicit-any*/ | ||
| import { Logger } from '../types/logger'; | ||
|
|
||
| /** | ||
| * Default console-based logger implementation. | ||
| * This logger uses the browser's console API to output log messages. | ||
| * Log level filtering is handled by the AmpLogger wrapper class. | ||
| * @category Logging | ||
| */ | ||
| export class ConsoleLogger implements Logger { | ||
| /** | ||
| * Log an error message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| error(message?: any, ...optionalParams: any[]): void { | ||
| console.error(message, ...optionalParams); | ||
| } | ||
|
|
||
| /** | ||
| * Log a warning message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| warn(message?: any, ...optionalParams: any[]): void { | ||
| console.warn(message, ...optionalParams); | ||
| } | ||
|
|
||
| /** | ||
| * Log an informational message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| info(message?: any, ...optionalParams: any[]): void { | ||
| console.info(message, ...optionalParams); | ||
| } | ||
|
|
||
| /** | ||
| * Log a debug message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| debug(message?: any, ...optionalParams: any[]): void { | ||
| console.debug(message, ...optionalParams); | ||
| } | ||
|
|
||
| /** | ||
| * Log a verbose message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| verbose(message?: any, ...optionalParams: any[]): void { | ||
| console.debug(message, ...optionalParams); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * Log level enumeration for controlling logging verbosity. | ||
| * @category Logging | ||
| */ | ||
| export enum LogLevel { | ||
| /** | ||
| * Disable all logging | ||
| */ | ||
| Disable = 0, | ||
| /** | ||
| * Error level logging - only critical errors | ||
| */ | ||
| Error = 1, | ||
| /** | ||
| * Warning level logging - errors and warnings | ||
| */ | ||
| Warn = 2, | ||
| /** | ||
| * Info level logging - errors, warnings, and informational messages | ||
| */ | ||
| Info = 3, | ||
| /** | ||
| * Debug level logging - errors, warnings, info, and debug messages | ||
| */ | ||
| Debug = 4, | ||
| /** | ||
| * Verbose level logging - all messages including verbose details | ||
| */ | ||
| Verbose = 5, | ||
| } | ||
|
|
||
| /** | ||
| * Logger interface that can be implemented to provide custom logging. | ||
| * @category Logging | ||
| */ | ||
| export interface Logger { | ||
| /** | ||
| * Log an error message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| error(message?: any, ...optionalParams: any[]): void; | ||
|
|
||
| /** | ||
| * Log a warning message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| warn(message?: any, ...optionalParams: any[]): void; | ||
|
|
||
| /** | ||
| * Log an informational message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| info(message?: any, ...optionalParams: any[]): void; | ||
|
|
||
| /** | ||
| * Log a debug message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| debug(message?: any, ...optionalParams: any[]): void; | ||
|
|
||
| /** | ||
| * Log a verbose message | ||
| * @param message The message to log | ||
| * @param optionalParams Additional parameters to log | ||
| */ | ||
| verbose(message?: any, ...optionalParams: any[]): void; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder the necessity of the wrapper given we're not doing any filtering or transformation like other SDKs. We usually want to keep
experiment-browserlean.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point about lean skds. I believe this is a low addition way to provide log level filtering on our end as well as have a decent buffer between our log level definitions/usages and others.