package org.springblade.risk.log.listener;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.event.UsualLogEvent;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author: lianghanqiang
 * @description:  系统自定义日志事件监听---日志收集
 * @since: 10/22/21 -- 3:05 PM
 */
@Slf4j
@Component
@AllArgsConstructor
public class LdtLogListener {

//	private  RabbitTemplate rabbitTemplate;

	@Async
	@EventListener({UsualLogEvent.class})
	public void saveApiLog(UsualLogEvent event) {
		String data = JSON.toJSONString(event.getSource());
//		rabbitTemplate.send("LogDirectExchange","LogDirectRouting",new Message(data.getBytes()));
		System.out.println(data);
	}
}
