From fe6b49673543db5dd49f98176c0509ff29139565 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 22 Dec 2024 08:35:29 +0800 Subject: [PATCH] fix: Transport log should return string type (#99) ## Summary by CodeRabbit - **New Features** - Added a badge for Node.js version compatibility to the README.md. - **Bug Fixes** - Updated the `log` method in the `Transport` class to return a string, enhancing its functionality. - **Chores** - Modified GitHub Actions workflow to include `CODECOV_TOKEN` for improved code coverage reporting. - Expanded type definitions in the test file by adding new imports for `Transport` and `LoggerLevel`. --- .github/workflows/nodejs.yml | 2 ++ README.md | 1 + index.d.ts | 2 +- index.test-d.ts | 10 +++++++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index f5d6393..2bd8dae 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -14,3 +14,5 @@ jobs: with: os: 'ubuntu-latest, macos-latest' version: '14.18.0, 14, 16, 18, 20, 22' + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/README.md b/README.md index 6ced472..a2db24d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![Test coverage][codecov-image]][codecov-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][download-url] +[![Node.js Version](https://img.shields.io/node/v/egg-logger.svg?style=flat)](https://nodejs.org/en/download/) [npm-image]: https://img.shields.io/npm/v/egg-logger.svg?style=flat-square [npm-url]: https://npmjs.org/package/egg-logger diff --git a/index.d.ts b/index.d.ts index cbfbf38..ae80a7f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -221,7 +221,7 @@ export class Transport { level: LoggerLevel; enable(): void; shouldLog(level: LoggerLevel): boolean; - log(level: LoggerLevel, args: any[], meta?: LoggerMeta): void; + log(level: LoggerLevel, args: any[], meta?: LoggerMeta): string; reload(): void; close(): void; end(): void; diff --git a/index.test-d.ts b/index.test-d.ts index 1788c42..661a7eb 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,6 +1,9 @@ import { expectType } from 'tsd'; import { AsyncLocalStorage } from 'async_hooks'; -import { EggLoggerOptions, Logger, EggContextLogger, EggConsoleLogger } from '.'; +import { + EggLoggerOptions, Logger, EggContextLogger, EggConsoleLogger, + Transport, LoggerLevel, +} from '.'; const options = { formatter(meta: any) { @@ -36,3 +39,8 @@ const consoleLogger = new EggConsoleLogger(); expectType(consoleLogger.size); expectType(new EggConsoleLogger({}).size); expectType(new EggConsoleLogger({ encoding: 'utf8' }).size); + +const transport = {} as Transport; +expectType(transport); +expectType(transport.level); +expectType(transport.log('ALL', []));