Skip to content

Commit 4f37397

Browse files
authored
feat: Added optional args to logger.log to format string only when log level applies (#706)
## Summary Message formatting is performance heavy. The logger takes formatted message as a parameter, which means message formatting is being done for all types of logs even in cases when the log level does not apply. This PR adds arguments array to the `log` function to carry token values. Logger already has the functionality to `sprintf` based on extra args if the log level applies. This will increase performance in cases where log level is restricted to more conservative ones such as `ERROR`. ## Test plan - All Unit tests pass - Manually tested thoroughly with optimizely-sdk package. A follow up PR for the main package will be created after this is merged and released.
1 parent f33af13 commit 4f37397

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/logging/src/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ class OptimizelyLogger implements LoggerFacade {
218218
* @param {string} [message]
219219
* @memberof OptimizelyLogger
220220
*/
221-
log(level: LogLevel | string, message: string): void {
221+
log(level: LogLevel | string, message: string, ...splat: any[]): void {
222222
this.internalLog(coerceLogLevel(level), {
223223
message,
224-
splat: [],
224+
splat,
225225
})
226226
}
227227

packages/logging/src/models.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export enum LogLevel {
2222
}
2323

2424
export interface LoggerFacade {
25-
log(level: LogLevel | string, message: string): void
25+
log(level: LogLevel | string, message: string, ...splat: any[]): void
2626

2727
info(message: string | Error, ...splat: any[]): void
2828

@@ -38,5 +38,5 @@ export interface LogManager {
3838
}
3939

4040
export interface LogHandler {
41-
log(level: LogLevel, message: string): void
42-
}
41+
log(level: LogLevel, message: string, ...splat: any[]): void
42+
}

0 commit comments

Comments
 (0)