Skip to content

Commit

Permalink
Added type declaration for custom prettifiers (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarmicki committed Jul 16, 2021
1 parent 35108d9 commit b32ffb5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ interface PrettyOptions_ {
* @example "time,hostname"
*/
ignore?: string;
/**
* Provides the ability to add a custom prettify function for specific log properties.
* `customPrettifiers` is an object, where keys are log properties that will be prettified
* and value is the prettify function itself.
* For example, if a log line contains a query property, you can specify a prettifier for it:
* @default {}
*
* @example
* ```typescript
* {
* customPrettifiers: {
* query: prettifyQuery
* }
* }
* //...
* const prettifyQuery = value => {
* // do some prettify magic
* }
* ```
*/
customPrettifiers?: Record<string, PinoPretty.Prettifier>;
}

declare namespace PinoPretty {
Expand Down
10 changes: 10 additions & 0 deletions test/types/pino-pretty.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const options: PinoPretty.PrettyOptions = {
translateTime: "UTC:h:MM:ss TT Z",
search: "foo == `bar`",
singleLine: false,
customPrettifiers: {
key: (value) => {
return value.toString().toUpperCase();
}
}
};

const options2: PrettyOptions = {
Expand All @@ -42,6 +47,11 @@ const options2: PrettyOptions = {
translateTime: "UTC:h:MM:ss TT Z",
search: "foo == `bar`",
singleLine: false,
customPrettifiers: {
key: (value) => {
return value.toString().toUpperCase();
}
}
};

const pretty = prettyFactory(options);
Expand Down

0 comments on commit b32ffb5

Please sign in to comment.