From e61aa002123da109881252e9e6ad56c36817353d Mon Sep 17 00:00:00 2001 From: Noah Gao Date: Tue, 28 Jun 2022 18:52:09 +0800 Subject: [PATCH] refactor(logger): rename args to splat (#119) --- src/logger/impl.ts | 16 ++++++++-------- src/logger/types.ts | 2 +- test/fixtures/logger/src/test_clazz.ts | 4 ++-- test/logger.test.ts | 24 ++++++++++++------------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/logger/impl.ts b/src/logger/impl.ts index 9fed2b1..73e46cb 100644 --- a/src/logger/impl.ts +++ b/src/logger/impl.ts @@ -54,32 +54,32 @@ export default class ArtusLogger extends BaseLogger { public log({ level, message, - args = [] + splat = [] }: LogOptions) { if (message instanceof Error) { if (level === LoggerLevel.ERROR) { - return this.error(message, ...args); + return this.error(message, ...splat); } message = message.stack ?? message.message; } switch (level) { case LoggerLevel.TRACE: - this.trace(message, ...args); + this.trace(message, ...splat); break; case LoggerLevel.DEBUG: - this.debug(message, ...args); + this.debug(message, ...splat); break; case LoggerLevel.INFO: - this.info(message, ...args); + this.info(message, ...splat); break; case LoggerLevel.WARN: - this.warn(message, ...args); + this.warn(message, ...splat); break; case LoggerLevel.ERROR: - this.error(message, ...args); + this.error(message, ...splat); break; case LoggerLevel.FATAL: - this.fatal(message, ...args); + this.fatal(message, ...splat); break; } } diff --git a/src/logger/types.ts b/src/logger/types.ts index f0d359d..4286d11 100644 --- a/src/logger/types.ts +++ b/src/logger/types.ts @@ -7,7 +7,7 @@ export interface LoggerOptions { export interface LogOptions { level: LoggerLevel; message: string|Error; - args?: any[]; + splat?: any[]; } export interface Logger { diff --git a/test/fixtures/logger/src/test_clazz.ts b/test/fixtures/logger/src/test_clazz.ts index c531feb..81b05fb 100644 --- a/test/fixtures/logger/src/test_clazz.ts +++ b/test/fixtures/logger/src/test_clazz.ts @@ -6,11 +6,11 @@ export default class TestLoggerClazz { @Inject() private logger!: ArtusLogger; - public testLog(level: LoggerLevel, message: string|Error, ...args: any[]) { + public testLog(level: LoggerLevel, message: string|Error, ...splat: any[]) { this.logger.log({ level, message, - args, + splat, }); } diff --git a/test/logger.test.ts b/test/logger.test.ts index 227fca6..432ed8c 100644 --- a/test/logger.test.ts +++ b/test/logger.test.ts @@ -61,21 +61,21 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.TRACE, message: 'trace', - args: [ 0, {} ] + splat: [ 0, {} ] }); expect(console.trace).toBeCalledTimes(0); app.logger.log({ level: LoggerLevel.DEBUG, message: 'debug', - args: [ 1, {} ] + splat: [ 1, {} ] }); expect(console.debug).toBeCalledTimes(0); app.logger.log({ level: LoggerLevel.INFO, message: 'info', - args: [ 2, {} ] + splat: [ 2, {} ] }); expect(console.info).toBeCalledTimes(1); expect(console.info).toBeCalledWith('info', 2, {}); @@ -83,7 +83,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.WARN, message: 'warn', - args: [ 3, {} ] + splat: [ 3, {} ] }); expect(console.warn).toBeCalledTimes(1); expect(console.warn).toBeCalledWith('warn', 3, {}); @@ -91,12 +91,12 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.ERROR, message: 'error', - args: [ 4, {} ] + splat: [ 4, {} ] }); app.logger.log({ level: LoggerLevel.ERROR, message: err, - args: [ 5, {} ] + splat: [ 5, {} ] }); expect(console.error).toBeCalledTimes(2); expect(console.error).toBeCalledWith('error', 4, {}); @@ -198,7 +198,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.TRACE, message: 'trace', - args: [ 0, {} ] + splat: [ 0, {} ] }); expect(console.trace).toBeCalledTimes(1); expect(console.trace).toBeCalledWith('trace', 0, {}); @@ -206,7 +206,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.DEBUG, message: 'debug', - args: [ 1, {} ] + splat: [ 1, {} ] }); expect(console.debug).toBeCalledTimes(1); expect(console.debug).toBeCalledWith('debug', 1, {}); @@ -214,7 +214,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.INFO, message: 'info', - args: [ 2, {} ] + splat: [ 2, {} ] }); expect(console.info).toBeCalledTimes(1); expect(console.info).toBeCalledWith('info', 2, {}); @@ -222,7 +222,7 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.WARN, message: 'warn', - args: [ 3, {} ] + splat: [ 3, {} ] }); expect(console.warn).toBeCalledTimes(1); expect(console.warn).toBeCalledWith('warn', 3, {}); @@ -230,12 +230,12 @@ describe('test/logger.test.ts', () => { app.logger.log({ level: LoggerLevel.ERROR, message: 'error', - args: [ 4, {} ] + splat: [ 4, {} ] }); app.logger.log({ level: LoggerLevel.ERROR, message: err, - args: [ 5, {} ] + splat: [ 5, {} ] }); expect(console.error).toBeCalledTimes(2); expect(console.error).toBeCalledWith('error', 4, {});