package dataQualityWebSite;

import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class LogFile 
{
	private FileWriter file;
	private String fileName;
	private Calendar today;
	private DateFormat longDateFormat;
	private DateFormat shortDateFormat;
		
	public LogFile(Configuration configuration, String fileNameRoot)
	{
    	today = Calendar.getInstance();
    	shortDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    	longDateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
		
    	fileName = new String
    	(
    		configuration.getLogFileLocation() +
    		fileNameRoot + 
    		shortDateFormat.format(today.getTime()) +
    		".log"
    	);
		
		try 
		{
			file = new FileWriter(fileName);
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
	
	public void logMessage (String message)
	{
		try 
		{
	    	today = Calendar.getInstance();
			file.write(longDateFormat.format(today.getTime()) + " " + message + "\n");
		} catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void Close()
	{
		try 
		{
			file.close();
		} catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
