diff --git a/packages/logger/README.md b/packages/logger/README.md index e69de29bb..465f209ba 100644 --- a/packages/logger/README.md +++ b/packages/logger/README.md @@ -0,0 +1,33 @@ +# Slack Logger + +The `@slack/logger` package is intended to be used as a simple logging interface that supports verbosity levels. + +## Requirements + +This package supports Node v18 and higher. It's highly recommended to use [the latest LTS version of +node](https://github.com/nodejs/Release#release-schedule), and the documentation is written using syntax and features +from that version. + +## Installation + +```shell +$ npm install @slack/logger +``` + +## Usage + +This package exports a `ConsoleLogger` class, a generic `Logger` interface and a `LogLevel` enum. +The source code is short (~150 lines of code), so check out `src/index.ts` for details, but the `ConsoleLogger` API +mimics the default node `console` API with three additions: + +- `getLevel()`: returns the currently-specific `LogLevel` of the logger. +- `setLevel(LogLevel)`: sets the `LogLevel` of the logger. +- `setName(string)`: sets a prefix to display in logs. Useful if you have multiple loggers active. + +## Getting Help + +If you get stuck, we're here to help. The following are the best ways to get assistance working through your issue: + + * [Issue Tracker](http://github.com/slackapi/node-slack-sdk/issues) for questions, feature requests, bug reports and + general discussion related to this package. Try searching before you create a new issue. + * [Email us](mailto:developers@slack.com) in Slack developer support: `developers@slack.com` diff --git a/packages/logger/package.json b/packages/logger/package.json index b58c7334b..bd3e7b740 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -14,8 +14,8 @@ "dist/**/*" ], "engines": { - "node": ">= 12.13.0", - "npm": ">= 6.12.0" + "node": ">= 18", + "npm": ">= 8.6.0" }, "repository": "slackapi/node-slack-sdk", "homepage": "https://slack.dev/node-slack-sdk", @@ -30,31 +30,34 @@ "build": "npm run build:clean && tsc", "build:clean": "shx rm -rf ./dist ./coverage ./.nyc_output", "lint": "eslint --ext .ts src", - "test": "npm run lint && npm run build && nyc mocha --config .mocharc.json src/*.spec.js", + "mocha": "mocha --config .mocharc.json src/*.spec.js", + "test:unit": "npm run build && npm run mocha", + "test": "npm run lint && npm run test:unit", + "coverage": "npm run build && nyc --reporter=text-summary npm run mocha", "ref-docs:model": "api-extractor run" }, "dependencies": { - "@types/node": ">=12.0.0" + "@types/node": ">=18.0.0" }, "devDependencies": { - "@microsoft/api-extractor": "^7.3.4", - "@typescript-eslint/eslint-plugin": "^4.4.1", - "@typescript-eslint/parser": "^4.4.0", - "@types/chai": "^4.1.7", - "@types/mocha": "^5.2.6", - "chai": "^4.2.0", - "eslint": "^7.32.0", - "eslint-config-airbnb-base": "^14.2.1", - "eslint-config-airbnb-typescript": "^12.3.1", - "eslint-plugin-import": "^2.22.1", - "eslint-plugin-jsdoc": "^30.6.1", + "@microsoft/api-extractor": "^7.36.4", + "@typescript-eslint/eslint-plugin": "^6.4.1", + "@typescript-eslint/parser": "^6.4.0", + "@types/chai": "^4.3.5", + "@types/mocha": "^10.0.1", + "chai": "^4.3.8", + "eslint": "^8.47.0", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-config-airbnb-typescript": "^17.1.0", + "eslint-plugin-import": "^2.28.1", + "eslint-plugin-jsdoc": "^46.5.0", "eslint-plugin-node": "^11.1.0", - "mocha": "^9.1.0", - "nyc": "^14.1.1", + "mocha": "^10.2.0", + "nyc": "^15.1.0", "shx": "^0.3.2", "ts-node": "^8.2.0", - "sinon": "^7.3.2", - "source-map-support": "^0.5.12", + "sinon": "^15.2.0", + "source-map-support": "^0.5.21", "typescript": "^4.1.0" } } diff --git a/packages/logger/src/index.ts b/packages/logger/src/index.ts index 7288c7d35..5f23f131a 100644 --- a/packages/logger/src/index.ts +++ b/packages/logger/src/index.ts @@ -16,36 +16,35 @@ export enum LogLevel { export interface Logger { /** * Output debug message - * * @param msg any data to log */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any debug(...msg: any[]): void; /** * Output info message - * * @param msg any data to log */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any info(...msg: any[]): void; /** * Output warn message - * * @param msg any data to log */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any warn(...msg: any[]): void; /** * Output error message - * * @param msg any data to log */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any error(...msg: any[]): void; /** * This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something") * or log.error("something") will output messages, but log.info("something") will not. - * * @param level as a string, like 'error' (case-insensitive) */ setLevel(level: LogLevel): void; @@ -58,7 +57,6 @@ export interface Logger { /** * This allows the instance to be named so that they can easily be filtered when many loggers are sending output * to the same destination. - * * @param name as a string, will be output with every log after the level */ setName(name: string): void; @@ -115,6 +113,7 @@ export class ConsoleLogger implements Logger { /** * Log a debug message */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any public debug(...msg: any[]): void { if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.DEBUG, this.level)) { console.debug(ConsoleLogger.labels.get(LogLevel.DEBUG), this.name, ...msg); @@ -124,6 +123,7 @@ export class ConsoleLogger implements Logger { /** * Log an info message */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any public info(...msg: any[]): void { if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.INFO, this.level)) { console.info(ConsoleLogger.labels.get(LogLevel.INFO), this.name, ...msg); @@ -133,6 +133,7 @@ export class ConsoleLogger implements Logger { /** * Log a warning message */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any public warn(...msg: any[]): void { if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.WARN, this.level)) { console.warn(ConsoleLogger.labels.get(LogLevel.WARN), this.name, ...msg); @@ -142,6 +143,7 @@ export class ConsoleLogger implements Logger { /** * Log an error message */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any public error(...msg: any[]): void { if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.ERROR, this.level)) { console.error(ConsoleLogger.labels.get(LogLevel.ERROR), this.name, ...msg);