package cn.meowrain.aioj.backend.framework.log;

import cn.meowrain.aioj.backend.framework.log.aspect.SysLogAspect;
import cn.meowrain.aioj.backend.framework.log.config.AIOJLogPropertiesConfiguration;
import cn.meowrain.aioj.backend.framework.log.event.SysLogListener;
import cn.meowrain.aioj.backend.upms.api.feign.RemoteLogService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(AIOJLogPropertiesConfiguration.class)
@ConditionalOnProperty(value = "aioj.log.enabled", matchIfMissing = true)
public class LogAutoConfiguration {

	/**
	 * 创建并返回SysLogListener的Bean实例
	 */
	@Bean
	@ConditionalOnBean(RemoteLogService.class)
	public SysLogListener sysLogListener(AIOJLogPropertiesConfiguration logProperties,
			RemoteLogService remoteLogService) {
		return new SysLogListener(remoteLogService, logProperties);
	}

	/**
	 * 返回切面类实例
	 * @return {@link SysLogAspect}
	 */
	@Bean
	public SysLogAspect sysLogAspect() {
		return new SysLogAspect();
	}

}
