nestjs-pino
Advanced tools
Comparing version 2.1.0 to 2.2.0-alpha.6310f7
@@ -88,7 +88,15 @@ "use strict"; | ||
if (Array.isArray(params)) { | ||
return [pinoHttp(...params), bindLoggerMiddleware]; | ||
const middleware = pinoHttp(...params); | ||
// @ts-expect-error: root is readonly field, but this is the place where | ||
// it's set actually | ||
PinoLogger_1.PinoLogger.root = middleware.logger; | ||
return [middleware, bindLoggerMiddleware]; | ||
} | ||
const middleware = pinoHttp(params); | ||
// @ts-expect-error: root is readonly field, but this is the place where | ||
// it's set actually | ||
PinoLogger_1.PinoLogger.root = middleware.logger; | ||
// FIXME: params type here is pinoHttp.Options | pino.DestinationStream | ||
// pinoHttp has two overloads, each of them takes those types | ||
return [pinoHttp(params), bindLoggerMiddleware]; | ||
return [middleware, bindLoggerMiddleware]; | ||
} | ||
@@ -95,0 +103,0 @@ function bindLoggerMiddleware(req, _res, next) { |
{ | ||
"name": "nestjs-pino", | ||
"version": "2.1.0", | ||
"version": "2.2.0-alpha.6310f7", | ||
"description": "Pino logger for NestJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,5 +6,10 @@ import * as pino from 'pino'; | ||
export declare class PinoLogger implements PinoMethods { | ||
/** | ||
* root is the most root logger that can be used to change params at runtime. | ||
* Accessible only when `useExisting` is not set to `true` in `Params`. | ||
* Readonly, but you can change it's properties. | ||
*/ | ||
static readonly root: pino.Logger; | ||
private context; | ||
private readonly contextName; | ||
private readonly opts; | ||
constructor({ pinoHttp, renameContext }: Params); | ||
@@ -11,0 +16,0 @@ trace(msg: string, ...args: any[]): void; |
@@ -25,2 +25,4 @@ "use strict"; | ||
outOfContext = undefined; | ||
// @ts-ignore reset root for tests only | ||
PinoLogger.root = undefined; | ||
} | ||
@@ -48,3 +50,2 @@ exports.__resetOutOfContextForTests = __resetOutOfContextForTests; | ||
this.contextName = renameContext || 'context'; | ||
this.opts = pinoHttp; | ||
} | ||
@@ -51,0 +52,0 @@ trace(...args) { |
@@ -409,2 +409,17 @@ <p align="center"> | ||
## Change pino params at runtime | ||
Pino root instance with passed via module registration params creates a separate child logger for every request. This root logger params can be changed at runtime via `PinoLogger.root` property which is the pointer to logger instance. Example: | ||
```ts | ||
@Controller('/') | ||
class TestController { | ||
@Post('/change-loggin-level') | ||
setLevel() { | ||
PinoLogger.root.level = 'info'; | ||
return null; | ||
} | ||
} | ||
``` | ||
## Migration | ||
@@ -534,4 +549,2 @@ | ||
--- | ||
Also if you are into NestJS ecosystem you may be interested in one of my other libs: | ||
@@ -538,0 +551,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
51791
482
619
1