-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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); | ||
| } | ||
| } | ||
| } | ||
| 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); | ||
| } | ||
| } |
| 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; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.