Skip to content

Commit

Permalink
feat: add debug option
Browse files Browse the repository at this point in the history
  • Loading branch information
espresse committed Mar 25, 2024
1 parent 64a80a8 commit 514240c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/message-dispatcher.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ExecutionContext,
Inject,
Injectable,
Logger,
NestInterceptor,
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
Expand All @@ -17,6 +18,8 @@ import { Options } from './options.dto';

@Injectable()
export class MessageDispatcherInterceptor implements NestInterceptor {
logger = new Logger(MessageDispatcherInterceptor.name);

constructor(
@Inject(AsyncLoggerProvider) private client: AsyncLoggerProvider,
private options: Options,
Expand Down Expand Up @@ -57,6 +60,10 @@ export class MessageDispatcherInterceptor implements NestInterceptor {
timestamp: timestamp(),
};

if (this.options.debug) {
this.logger.debug(this.options.subject, JSON.stringify(sendData));
}

await this.client.log(this.options.subject, sendData);
}
}),
Expand Down
1 change: 1 addition & 0 deletions src/options.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { Message } from './message.dto';
export class Options {
subject: string;
messageData: Message;
debug?: boolean;
}

0 comments on commit 514240c

Please sign in to comment.