Repository: artusjs/core
Pull request #119 (2022-06-28 10:42:28)

refactor(logger): rename args to splat
对齐日志库常用参数 splat


Patch:
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 {


Test patch:
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, {});