Skip to content

Commit

Permalink
add fatal level support
Browse files Browse the repository at this point in the history
  • Loading branch information
iamolegga committed Aug 21, 2023
1 parent 951034e commit 0025d86
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 53 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,13 @@ In NestJS <= 7 and `nestjs-pino@1` when you call `this.logger.log('foo', 'bar');
**A**: Pino built-in methods names are not fully compatible with NestJS built-in `LoggerService` methods names, and there is an option which logger you use. Here is methods mapping:

| `pino` method | `PinoLogger` method | NestJS built-in `Logger` method |
| ------------- | ------------------- | --------------- |
| **trace** | **trace** | **verbose** |
| debug | debug | debug |
| **info** | **info** | **log** |
| warn | warn | warn |
| error | error | error |
| **fatal** | **fatal** | - |
| ------------- | ------------------- | --------------------------------|
| **trace** | **trace** | **verbose** |
| debug | debug | debug |
| **info** | **info** | **log** |
| warn | warn | warn |
| error | error | error |
| fatal | fatal | fatal (since [email protected]) |

---

Expand Down
14 changes: 12 additions & 2 deletions __tests__/levels.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { Controller, Get, Logger } from '@nestjs/common';
import {
Controller,
Get,
Logger,
ConsoleLogger,
LogLevel,
} from '@nestjs/common';
import pino from 'pino';

import { PinoLogger } from '../src';

import { platforms } from './utils/platforms';
import { TestCase } from './utils/test-case';

const loggerMethods: [Exclude<keyof Logger, 'localInstance'>, pino.Level][] = [
const loggerMethods: [LogLevel, pino.Level][] = [
['verbose', 'trace'],
['debug', 'debug'],
['log', 'info'],
['warn', 'warn'],
['error', 'error'],
];

// the only way to make it work across different versions of nestjs
if (ConsoleLogger.prototype.hasOwnProperty('fatal'))
loggerMethods.push([<LogLevel>'fatal', 'fatal']);

const pinoLoggerMethods: pino.Level[] = loggerMethods
.map((p) => p[1])
.concat('fatal');
Expand Down
74 changes: 37 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@
},
"homepage": "https://github.com/iamolegga/nestjs-pino#readme",
"devDependencies": {
"@nestjs/common": "^10.1.3",
"@nestjs/core": "^10.1.3",
"@nestjs/platform-express": "^10.1.3",
"@nestjs/platform-fastify": "^10.1.3",
"@nestjs/testing": "^10.1.3",
"@nestjs/common": "^10.2.0",
"@nestjs/core": "^10.2.0",
"@nestjs/platform-express": "^10.2.0",
"@nestjs/platform-fastify": "^10.2.0",
"@nestjs/testing": "^10.2.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.3",
"@types/memorystream": "^0.3.1",
"@types/node": "^20.5.0",
"@types/node": "^20.5.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"jest": "29.6.2",
"memorystream": "^0.3.1",
Expand Down
4 changes: 4 additions & 0 deletions src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class Logger implements LoggerService {
this.call('error', message, ...optionalParams);
}

fatal(message: any, ...optionalParams: any[]) {
this.call('fatal', message, ...optionalParams);
}

private call(level: Level, message: any, ...optionalParams: any[]) {
const objArg: Record<string, any> = {};

Expand Down

0 comments on commit 0025d86

Please sign in to comment.