package com;

import com.haobang.config.AppProperties;
import com.haobang.config.SyslogConfig;
import com.kafka.kafkaProducer;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import com.netty.SyslogServer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.netty.SyslogServerBoth;


@MapperScan("com.common.mapper")
@SpringBootApplication
@EnableScheduling
public class SyslogServeMainApp {

    private static final Logger logger = LoggerFactory.getLogger(SyslogServeMainApp.class);

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SyslogServeMainApp.class, args);
        Environment env = context.getEnvironment();
        try {
            int tcpPort = args.length > 0 ? Integer.parseInt(args[0])
                    : Integer.parseInt(env.getProperty("syslog.tcp.port", "514"));
            int udpPort = args.length > 1 ? Integer.parseInt(args[1])
                    : Integer.parseInt(env.getProperty("syslog.udp.port", "515"));
            SyslogServerBoth server = new SyslogServerBoth(tcpPort, udpPort);
            logger.info("Application SyslogServer start !");
            server.start();

        }catch ( Exception ex)
        {
            System.out.println("Application Catch Error message: "+ex.getMessage());
            logger.error("Application Catch Error message: "+ex.getMessage());
        }
    }
}
