Skip to content

Commit

Permalink
Update pino types for browser.formatters (#1946)
Browse files Browse the repository at this point in the history
  • Loading branch information
KatelynKim authored Apr 28, 2024
1 parent 293b27c commit b50d02b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pino.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ declare namespace pino {
* pino.info('hi') // creates and logs {msg: 'hi', level: 30, time: <ts>}
*/
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<string, unknown>) => Record<string, unknown>;
}
/**
* 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
Expand Down
18 changes: 17 additions & 1 deletion test/types/pino-type-only.test-d.ts
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down Expand Up @@ -46,3 +46,19 @@ const needsMetadata: typeof pino.symbols.needsMetadataGsym = pino.symbols.needsM
if (stream[needsMetadata]) {
expectType<number>(stream.lastLevel);
}

const loggerOptions:LoggerOptions = {
browser: {
formatters: {
log(obj) {
return obj
},
level(label, number) {
return { label, number}
}

}
}
}

expectType<LoggerOptions>(loggerOptions)

0 comments on commit b50d02b

Please # to comment.