/**
 * 
 */
package org.josast.ApplicationAmicalsat.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;

/**
 * @author christophe
 *
 */
public class LogFile {

    private Logger appLogger = Logger.getLogger("AmicalSatLogger");
    private PrintWriter pw;
    
    /**
     * 
     */
    public LogFile() {
        // TODO Auto-generated constructor stub
        initdisplayLogFile();
    }

    
    private void initdisplayLogFile()
    {

        
        SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd-HHmmss");
        Date aujourdhui = new Date();
        String path = System.getProperty("user.dir") + "/log";
        File apath = new File(path);

        if (!apath.exists()) {
            if (apath.mkdir() == false) {
                appLogger.severe("fail to create " + path);
            }
        }
        try {
             pw = new PrintWriter (new FileWriter(path+"/"+formater.format(aujourdhui)+"-"+".log"));
        } catch (IOException e) {
            appLogger.severe("erreur creating log file");
            appLogger.severe (e.toString());
        }
    }
    
    public  void displayLog(String log) {
        if(pw!=null)
        {
          pw.println(log);
          pw.flush();
        }
        appLogger.info(log);

    }
    
    
}
