fix: Added log when send event to rabbitMQ and Websocket

This commit is contained in:
Davidson Gomes 2023-08-31 18:24:30 -03:00
parent 6eda556242
commit 7e4dbfdd7e
3 changed files with 38 additions and 2 deletions

View File

@ -43,7 +43,6 @@ export const getAMQP = (): amqp.Channel | null => {
};
export const initQueues = (instanceName: string, events: string[]) => {
console.log('initQueues', instanceName, events);
if (!events || !events.length) return;
const queues = events.map((event) => {

View File

@ -5,7 +5,6 @@ import EventEmitter2 from 'eventemitter2';
import { ConfigService, HttpServer } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
import { initQueues } from '../../libs/amqp.server';
import { RedisCache } from '../../libs/redis.client';
import { InstanceDto } from '../dto/instance.dto';
import { RepositoryBroker } from '../repository/repository.manager';

View File

@ -688,6 +688,25 @@ export class WAStartupService {
}
amqp.publish(exchangeName, event, Buffer.from(JSON.stringify(message)));
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
const logData = {
local: WAStartupService.name + '.sendData-RabbitMQ',
event,
instance: this.instance.name,
data,
server_url: serverUrl,
apikey: (expose && instanceApikey) || null,
date_time: now,
sender: this.wuid,
};
if (expose && instanceApikey) {
logData['apikey'] = instanceApikey;
}
this.logger.log(logData);
}
}
}
}
@ -713,6 +732,25 @@ export class WAStartupService {
this.logger.verbose('Sending data to socket.io in channel: ' + this.instance.name);
io.of(`/${this.instance.name}`).emit(event, message);
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
const logData = {
local: WAStartupService.name + '.sendData-Websocket',
event,
instance: this.instance.name,
data,
server_url: serverUrl,
apikey: (expose && instanceApikey) || null,
date_time: now,
sender: this.wuid,
};
if (expose && instanceApikey) {
logData['apikey'] = instanceApikey;
}
this.logger.log(logData);
}
}
}