From 29c62b67aad210e02cb465c78e5678b8dcf4bb6a Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Thu, 26 Aug 2021 20:27:03 +0300 Subject: [PATCH 1/7] Remove obsolete typings Fix index type --- package.json | 2 +- pino.d.ts | 16 +--------------- test/types/pino.test-d.ts | 6 +++++- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index fb7bf248b..1251ac569 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "bunyan": "^1.8.14", "docsify-cli": "^4.4.1", "eslint": "^7.17.0", - "eslint-config-standard": "^16.0.2", + "eslint-config-standard": "^16.0.3", "eslint-plugin-import": "^2.22.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", diff --git a/pino.d.ts b/pino.d.ts index 0e8e1ff02..d48ef19e4 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -50,7 +50,6 @@ declare namespace P { /** * Holds the current log format version (as output in the v property of each log record). */ - const LOG_VERSION: number; const levels: LevelMapping; const symbols: { readonly setLevelSym: unique symbol; @@ -728,22 +727,9 @@ declare namespace P { }; } - type Logger = BaseLogger & { [key: string]: LogFn }; + type Logger = BaseLogger & Record; interface BaseLogger extends EventEmitter { - /** - * Exposes the current version of Pino. - */ - readonly pino: string; - /** - * Holds the current log format version (as output in the v property of each log record). - */ - readonly LOG_VERSION: number; - /** - * Exposes the Pino package version. Also available on the exported pino function. - */ - readonly version: string; - levels: LevelMapping; /** diff --git a/test/types/pino.test-d.ts b/test/types/pino.test-d.ts index d6f8c5391..b41fd92f6 100644 --- a/test/types/pino.test-d.ts +++ b/test/types/pino.test-d.ts @@ -106,7 +106,7 @@ childRedacted.info({ msg: "logged with redacted properties", path: "Not shown", }); -const childAnotherRedacted = pino().child({}, { +const childAnotherRedacted = pino().child({}, { redact: { paths: ["anotherPath"], censor: "Not the log you\re looking for", @@ -267,3 +267,7 @@ const logLine: pino.LogDescriptor = { time: new Date().getTime(), aCustomProperty: true, }; + +interface CustomLogger extends pino.Logger { + customMethod(msg: string, ...args: unknown[]): void; +} From b891d4fa09d627124fc1cd6d555fb5674633c846 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Thu, 26 Aug 2021 21:00:19 +0300 Subject: [PATCH 2/7] Restore field which is still present --- pino.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pino.d.ts b/pino.d.ts index d48ef19e4..2cc74b426 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -730,6 +730,11 @@ declare namespace P { type Logger = BaseLogger & Record; interface BaseLogger extends EventEmitter { + /** + * Exposes the Pino package version. Also available on the exported pino function. + */ + readonly version: string; + levels: LevelMapping; /** From 20fff9f09185fb3ad57c081a3446cea35e854afa Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Thu, 26 Aug 2021 21:07:08 +0300 Subject: [PATCH 3/7] Split logger into base and extra --- pino.d.ts | 118 +++++++++++++++++++++++++++--------------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/pino.d.ts b/pino.d.ts index 2cc74b426..907d8df05 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -727,64 +727,9 @@ declare namespace P { }; } - type Logger = BaseLogger & Record; - - interface BaseLogger extends EventEmitter { - /** - * Exposes the Pino package version. Also available on the exported pino function. - */ - readonly version: string; - - levels: LevelMapping; - - /** - * Set this property to the desired logging level. In order of priority, available levels are: - * - * - 'fatal' - * - 'error' - * - 'warn' - * - 'info' - * - 'debug' - * - 'trace' - * - * The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`, - * and `'info'` logs will be enabled. - * - * You can pass `'silent'` to disable logging. - */ - level: LevelWithSilent | string; - /** - * Outputs the level as a string instead of integer. - */ - useLevelLabels: boolean; - /** - * Define additional logging levels. - */ - customLevels: { [key: string]: number }; - /** - * Use only defined `customLevels` and omit Pino's levels. - */ - useOnlyCustomLevels: boolean; - /** - * Returns the integer value for the logger instance's logging level. - */ - levelVal: number; - - /** - * Registers a listener function that is triggered when the level is changed. - * Note: When browserified, this functionality will only be available if the `events` module has been required elsewhere - * (e.g. if you're using streams in the browser). This allows for a trade-off between bundle size and functionality. - * - * @param event: only ever fires the `'level-change'` event - * @param listener: The listener is passed four arguments: `levelLabel`, `levelValue`, `previousLevelLabel`, `previousLevelValue`. - */ - on(event: "level-change", listener: LevelChangeEventListener): this; - addListener(event: "level-change", listener: LevelChangeEventListener): this; - once(event: "level-change", listener: LevelChangeEventListener): this; - prependListener(event: "level-change", listener: LevelChangeEventListener): this; - prependOnceListener(event: "level-change", listener: LevelChangeEventListener): this; - removeListener(event: "level-change", listener: LevelChangeEventListener): this; + type Logger = BaseLogger & LoggerExtras & Record; + interface BaseLogger { /** * Creates a child logger, setting all key-value pairs in `bindings` as properties in the log lines. All serializers will be applied to the given pair. * Child loggers use the same output stream as the parent and inherit the current log level of the parent at the time they are spawned. @@ -795,7 +740,7 @@ declare namespace P { * @param options: an options object that will override child logger inherited options. * @returns a child logger instance. */ - child(bindings: Bindings, options?: ChildLoggerOptions): Logger; + child(bindings: Bindings, options?: ChildLoggerOptions): T; /** * Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. @@ -861,6 +806,63 @@ declare namespace P { * Noop function. */ silent: LogFn; + } + + interface LoggerExtras extends EventEmitter { + /** + * Exposes the Pino package version. Also available on the exported pino function. + */ + readonly version: string; + + levels: LevelMapping; + + /** + * Set this property to the desired logging level. In order of priority, available levels are: + * + * - 'fatal' + * - 'error' + * - 'warn' + * - 'info' + * - 'debug' + * - 'trace' + * + * The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`, + * and `'info'` logs will be enabled. + * + * You can pass `'silent'` to disable logging. + */ + level: LevelWithSilent | string; + /** + * Outputs the level as a string instead of integer. + */ + useLevelLabels: boolean; + /** + * Define additional logging levels. + */ + customLevels: { [key: string]: number }; + /** + * Use only defined `customLevels` and omit Pino's levels. + */ + useOnlyCustomLevels: boolean; + /** + * Returns the integer value for the logger instance's logging level. + */ + levelVal: number; + + /** + * Registers a listener function that is triggered when the level is changed. + * Note: When browserified, this functionality will only be available if the `events` module has been required elsewhere + * (e.g. if you're using streams in the browser). This allows for a trade-off between bundle size and functionality. + * + * @param event: only ever fires the `'level-change'` event + * @param listener: The listener is passed four arguments: `levelLabel`, `levelValue`, `previousLevelLabel`, `previousLevelValue`. + */ + on(event: "level-change", listener: LevelChangeEventListener): this; + addListener(event: "level-change", listener: LevelChangeEventListener): this; + once(event: "level-change", listener: LevelChangeEventListener): this; + prependListener(event: "level-change", listener: LevelChangeEventListener): this; + prependOnceListener(event: "level-change", listener: LevelChangeEventListener): this; + removeListener(event: "level-change", listener: LevelChangeEventListener): this; /** * A utility method for determining if a given log level will write to the destination. From f0b7d5c84606f0c1f1a3ac8614e44a4d3f0371e9 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Thu, 26 Aug 2021 21:17:53 +0300 Subject: [PATCH 4/7] Drop unnecessary generic --- pino.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pino.d.ts b/pino.d.ts index 907d8df05..f4a079b8d 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -740,7 +740,7 @@ declare namespace P { * @param options: an options object that will override child logger inherited options. * @returns a child logger instance. */ - child(bindings: Bindings, options?: ChildLoggerOptions): T; + child(bindings: Bindings, options?: ChildLoggerOptions): BaseLogger; /** * Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. From 6a9d48e1679ebffa2c12c49948b9261e228cd931 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Thu, 26 Aug 2021 21:32:57 +0300 Subject: [PATCH 5/7] Adjust types further --- pino.d.ts | 33 +++++++++++++++++---------------- test/types/pino.test-d.ts | 3 ++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pino.d.ts b/pino.d.ts index f4a079b8d..85d9d080f 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -742,6 +742,23 @@ declare namespace P { */ child(bindings: Bindings, options?: ChildLoggerOptions): BaseLogger; + /** + * Set this property to the desired logging level. In order of priority, available levels are: + * + * - 'fatal' + * - 'error' + * - 'warn' + * - 'info' + * - 'debug' + * - 'trace' + * + * The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`, + * and `'info'` logs will be enabled. + * + * You can pass `'silent'` to disable logging. + */ + level: LevelWithSilent | string; + /** * Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. * If more args follows `msg`, these will be used to format `msg` using `util.format`. @@ -816,22 +833,6 @@ declare namespace P { levels: LevelMapping; - /** - * Set this property to the desired logging level. In order of priority, available levels are: - * - * - 'fatal' - * - 'error' - * - 'warn' - * - 'info' - * - 'debug' - * - 'trace' - * - * The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`, - * and `'info'` logs will be enabled. - * - * You can pass `'silent'` to disable logging. - */ - level: LevelWithSilent | string; /** * Outputs the level as a string instead of integer. */ diff --git a/test/types/pino.test-d.ts b/test/types/pino.test-d.ts index b41fd92f6..b6369a808 100644 --- a/test/types/pino.test-d.ts +++ b/test/types/pino.test-d.ts @@ -1,6 +1,7 @@ import P, { pino } from "../../"; import { IncomingMessage, ServerResponse } from "http"; import { Socket } from "net"; +import Logger = P.Logger; const log = pino(); const info = log.info; @@ -92,7 +93,7 @@ child.level = "info"; child.info("hooray"); log.info("nope nope nope"); log.child({ foo: "bar" }, { level: "debug" }).debug("debug!"); -child.bindings(); +(child as Logger).bindings(); const customSerializers = { test() { return "this is my serializer"; From 2fbfc803a22a4548b54a68c84e7bb5d382385736 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Thu, 26 Aug 2021 23:01:37 +0300 Subject: [PATCH 6/7] Having child on extras provides better developer experience --- pino.d.ts | 24 ++++++++++++------------ test/types/pino.test-d.ts | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pino.d.ts b/pino.d.ts index 85d9d080f..a29952460 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -730,18 +730,6 @@ declare namespace P { type Logger = BaseLogger & LoggerExtras & Record; interface BaseLogger { - /** - * Creates a child logger, setting all key-value pairs in `bindings` as properties in the log lines. All serializers will be applied to the given pair. - * Child loggers use the same output stream as the parent and inherit the current log level of the parent at the time they are spawned. - * From v2.x.x the log level of a child is mutable (whereas in v1.x.x it was immutable), and can be set independently of the parent. - * If a `level` property is present in the object passed to `child` it will override the child logger level. - * - * @param bindings: an object of key-value pairs to include in log lines as properties. - * @param options: an options object that will override child logger inherited options. - * @returns a child logger instance. - */ - child(bindings: Bindings, options?: ChildLoggerOptions): BaseLogger; - /** * Set this property to the desired logging level. In order of priority, available levels are: * @@ -850,6 +838,18 @@ declare namespace P { */ levelVal: number; + /** + * Creates a child logger, setting all key-value pairs in `bindings` as properties in the log lines. All serializers will be applied to the given pair. + * Child loggers use the same output stream as the parent and inherit the current log level of the parent at the time they are spawned. + * From v2.x.x the log level of a child is mutable (whereas in v1.x.x it was immutable), and can be set independently of the parent. + * If a `level` property is present in the object passed to `child` it will override the child logger level. + * + * @param bindings: an object of key-value pairs to include in log lines as properties. + * @param options: an options object that will override child logger inherited options. + * @returns a child logger instance. + */ + child(bindings: Bindings, options?: ChildLoggerOptions): Logger; + /** * Registers a listener function that is triggered when the level is changed. * Note: When browserified, this functionality will only be available if the `events` module has been required elsewhere diff --git a/test/types/pino.test-d.ts b/test/types/pino.test-d.ts index b6369a808..b3c934bca 100644 --- a/test/types/pino.test-d.ts +++ b/test/types/pino.test-d.ts @@ -93,7 +93,7 @@ child.level = "info"; child.info("hooray"); log.info("nope nope nope"); log.child({ foo: "bar" }, { level: "debug" }).debug("debug!"); -(child as Logger).bindings(); +child.bindings(); const customSerializers = { test() { return "this is my serializer"; From e55e3291a1faa76eb1485b42d76080407b8e505b Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Fri, 27 Aug 2021 08:17:13 +0300 Subject: [PATCH 7/7] Bump few dependencies --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1251ac569..32161e79b 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ }, "homepage": "http://getpino.io", "devDependencies": { - "@types/node": "^16.4.10", + "@types/node": "^16.7.2", "airtap": "4.0.3", "benchmark": "^2.1.4", "bole": "^4.0.0", @@ -92,9 +92,9 @@ "tap": "^15.0.1", "tape": "^5.0.0", "through2": "^4.0.0", - "ts-node": "^10.0.0", + "ts-node": "^10.2.1", "tsd": "^0.17.0", - "typescript": "^4.3.5", + "typescript": "^4.4.2", "winston": "^3.3.3" }, "dependencies": {