package uy.edu.udelar.forrest.forrestloganalyser.model;


import org.apache.log4j.*;
 
/**
 *
 * @author pmarrero
 */
public class MyLogger {
    
    private boolean isOpen;
    
    private String fileConfig;

    private Logger logger;

    /** Creates a new instance of Logger */
    public MyLogger() {
        isOpen=false;
        fileConfig="";
    }
    
    public void openLogger(){
        if (isOpen){
            logWarn("MyLogger::openLogger - El loger ya está abierto.");
        }else if (fileConfig!=""){
            logger = Logger.getLogger("ForestLogAnalyser");
            PropertyConfigurator.configure(fileConfig);
            logger.info("Inicializada la carga de logs");
            isOpen=true;
        }else{
            isOpen=false;
        }
    }

    public void closeLogger(){
        if (isOpen){
            isOpen=false;
        }
    }

    public boolean isLoggerOpen(){
        return isOpen;
    };

    public void setLogConfigFileName(String logFile){
        fileConfig=logFile;
    }
  
    public String getLogConfigFileName(){
        return fileConfig;
    }

    public void logDebug(String message){
        logger.debug(message);
    }
    
    public void logInfo(String message){
        logger.info(message);
    }

    public void logWarn(String message){
        logger.warn(message);
    }
    
    public void logError(String message){
        logger.error(message);
    }
    
    public void logFatal(String message){
        logger.fatal(message);
    }
}

