package gethistprices;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.io.File;
import java.text.MessageFormat;

public class SimpleLog {
    
    private Writer mWriter;
    
    private String mLineSeparator;

    public SimpleLog(String sFilePath) throws IOException
    {
        mLineSeparator = System.getProperty("line.separator");
        try {
            System.out.println(sFilePath);
            File mLogFile = new File(sFilePath);
            if(!mLogFile.exists())
            {
                mLogFile.createNewFile();
            }
            mWriter = new OutputStreamWriter(new FileOutputStream(mLogFile), "ASCII");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public synchronized void log(String sLogMessage, Object ... args)
    {
        String sString = MessageFormat.format(sLogMessage, args);       
        System.out.println(sString);
        try {
            mWriter.write(sString);
            mWriter.write(mLineSeparator);
            mWriter.flush();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}