From edfd53c0f726f48bb41c562626700019b7e5f0b8 Mon Sep 17 00:00:00 2001 From: Katelyn Kim Date: Mon, 22 Apr 2024 16:01:03 -0700 Subject: [PATCH 1/2] Update pino types for browser.formatters --- pino.d.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pino.d.ts b/pino.d.ts index 41ffdfb4c..b6709a59d 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -427,6 +427,17 @@ declare namespace pino { * pino.info('hi') // creates and logs {msg: 'hi', level: 30, time: } */ asObject?: boolean; + formatters?: { + /** + * Changes the shape of the log level. + * The default shape is { level: number }. + */ + level?: (label: string, number: number) => object; + /** + * Changes the shape of the log object. + */ + log?: (object: Record) => Record; + } /** * Instead of passing log messages to `console.log` they can be passed to a supplied function. If `write` is * set to a single function, all logging objects are passed to this function. If `write` is an object, it From f42308af0c0d1d997ed496897ddda77dc3d61e08 Mon Sep 17 00:00:00 2001 From: Katelyn Kim Date: Fri, 26 Apr 2024 11:29:57 -0700 Subject: [PATCH 2/2] Add a test for browser.formatters type --- test/types/pino-type-only.test-d.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/types/pino-type-only.test-d.ts b/test/types/pino-type-only.test-d.ts index 4f1053f43..eb6221dcc 100644 --- a/test/types/pino-type-only.test-d.ts +++ b/test/types/pino-type-only.test-d.ts @@ -1,7 +1,7 @@ import { expectAssignable, expectType, expectNotAssignable } from "tsd"; import pino from "../../"; -import type {LevelWithSilent, Logger, LogFn, P, DestinationStreamWithMetadata, Level, LevelOrString, LevelWithSilentOrString, LoggerExtras } from "../../pino"; +import type {LevelWithSilent, Logger, LogFn, P, DestinationStreamWithMetadata, Level, LevelOrString, LevelWithSilentOrString, LoggerExtras, LoggerOptions } from "../../pino"; // NB: can also use `import * as pino`, but that form is callable as `pino()` // under `esModuleInterop: false` or `pino.default()` under `esModuleInterop: true`. @@ -46,3 +46,19 @@ const needsMetadata: typeof pino.symbols.needsMetadataGsym = pino.symbols.needsM if (stream[needsMetadata]) { expectType(stream.lastLevel); } + +const loggerOptions:LoggerOptions = { + browser: { + formatters: { + log(obj) { + return obj + }, + level(label, number) { + return { label, number} + } + + } + } +} + +expectType(loggerOptions)