Skip to content

Commit

Permalink
Add fatal logging method
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloanan authored and gremo committed Jan 15, 2024
1 parent 3b49136 commit a48aaa2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export class AppModule {}
debug(message: any, context?: string)
log(message: any, context?: string)
error(message: any, stack?: string, context?: string)
fatal(message: any, stack?: string, context?: string)
verbose(message: any, context?: string)
warn(message: any, context?: string)
```
Expand Down
19 changes: 19 additions & 0 deletions src/winston.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ export class WinstonLogger implements LoggerService {
return this.logger.info(message, { context });
}

public fatal(message: any, trace?: string, context?: string): any {
context = context || this.context;

if (message instanceof Error) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { message: msg, name, stack, ...meta } = message;

return this.logger.log({ level: 'fatal', message: msg, context, stack: [trace || stack], error: message, ...meta });
}

if (!!message && 'object' === typeof message) {
const { message: msg, ...meta } = message;

return this.logger.error({ level: 'fatal', message: msg, context, stack: [trace], ...meta });
}

return this.logger.error({ level: 'fatal', message, context, stack: [trace] });
}

public error(message: any, trace?: string, context?: string): any {
context = context || this.context;

Expand Down

0 comments on commit a48aaa2

Please sign in to comment.