Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger updates: dependencies and higher minimum node version #1650

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/logger/README.md
Original file line number Diff line number Diff line change
@@ -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:[email protected]) in Slack developer support: `[email protected]`
41 changes: 22 additions & 19 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
14 changes: 8 additions & 6 deletions packages/logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading