package salidasautomaticas.main;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;

import salidasautomaticas.schedule.ProgramarSalidasTask;
import salidasautomaticas.util.Metodos;

public class Main {
    private static final Logger log = LogManager.getLogger(Main.class);
    
    public static void main(String[] args){
        setLogLevel(Level.TRACE);      
        log.info("Inicializando programa [Salidas Automaticas]...");
  
        Date horaInicio = Metodos.getHoraEjecucion("12:00");
        int periodo = 86400000;//El codigo se ejecutará cada 24h, 86400000 representa 24h en milisegundos
        
        TimerTask task = new ProgramarSalidasTask();
        Timer timer = new Timer();
        timer.schedule(task , horaInicio, periodo);
    }
    
    
      private static void setLogLevel(Level l) {
        log.info("Setting log level to " + l.name());
        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        Configuration conf = ctx.getConfiguration();
        conf.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).setLevel(l);
        ctx.updateLoggers(conf);
    }

}
