<commit_before>package com.main.log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.os.Environment;

public class Logger {
	private static String filename = Environment.getExternalStorageDirectory() + "/QRCard/QRCard.log";

	private FileOutputStream fout;

	private static Logger instance;
	
	private static FileWriter writer;


	private Logger() {
		File file = new File(filename);
		if (file.exists()) {
			file.delete();
		}
		try {
			file.createNewFile();
		} catch (IOException e) {
			return;
		}
		try {
			fout = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			return;
		}
	}

	private void writeToFile(String msg) {
		try {
			fout.write(msg.getBytes());
			fout.write('\r');
			fout.write('\n');
			fout.write('\n');
			fout.flush();
		} catch (Exception e) {
		}
	}

	private void closeFout() {
		try {
			fout.close();
		} catch (Exception e) {
		}
	}

	public static synchronized Logger getInstance() {
		if (instance == null) {
			instance = new Logger();
		}
		return instance;
	}

	public static synchronized void close() {
		if (instance != null) {
			instance.closeFout();
			instance = null;
		}
	}

	public static synchronized void write(String msg) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		Date now = Calendar.getInstance().getTime();
		getInstance().writeToFile(String.format("%s--%s", df.format(now),msg));
	}
	
	
	public static synchronized void openWriter(String filepath, boolean overwrite){
		String filenameLog=null;
		if(filepath.startsWith("/"))
			filenameLog = Environment.getExternalStorageDirectory()+filepath;
		else
			filenameLog = Environment.getExternalStorageDirectory()+"/"+filepath;
	
		try {
			if(writer!=null){
				writer.close();
			}
			writer = new FileWriter(filenameLog,!overwrite);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static synchronized void writeToLog(String msg) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		Date now = Calendar.getInstance().getTime();

		try {
			if(writer!=null)
				writer.write(String.format("%s--%s\r\n", df.format(now),msg));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static synchronized void closeWriter(){
		if(writer!=null){
			try {
				writer.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			writer = null;
		}
	}
}
<commit_msg>save log to QRCardTest.txt/QRCard.log<commit_after>package com.main.log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.os.Environment;

public class Logger {
	private static String DRI_NAME = Environment.getExternalStorageDirectory() + "/QRCard";
	private static String FILE_FOR_TEST_NAME = DRI_NAME + "/QRCardTest.txt";
	private static String FILE_NAME = DRI_NAME + "/QRCard.log";
	private static int MAX_FILE_SIZE = 1024*100;
	private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	private static Logger instance;
	private FileOutputStream fout;
	private static FileWriter writer;


	private Logger() {
		boolean ret = false;
		File destDir = new File(DRI_NAME);
		if (!destDir.exists()) {
			ret = destDir.mkdirs();
		}
		
		File file = new File(FILE_NAME);	
		if (file.exists()&&file.length()>MAX_FILE_SIZE) {
			file.delete();
		}	
		if(!file.exists()){
			try {
				file.createNewFile();
			} catch (IOException e) {
				return;
			}
		}

		file = new File(FILE_FOR_TEST_NAME);
		long length = file.length();
		if (file.exists()&&file.length()>0) {
			file.delete();
		}	
		if(!file.exists()){
			try {
				file.createNewFile();
			} catch (IOException e) {
				return;
			}
		}
	}

	private void closeFout() {
		try {
			fout.close();
		} catch (Exception e) {
		}
	}

	public static synchronized Logger getInstance() {
		if (instance == null) {
			instance = new Logger();
		}
		return instance;
	}

	public static synchronized void close() {
		if (instance != null) {
			instance.closeFout();
			instance = null;
		}
	}

	public static synchronized void writeForTest(String msg) {
		Date now = Calendar.getInstance().getTime();
		getInstance().writeToLog(FILE_FOR_TEST_NAME, String.format("%s--%s\r\n", df.format(now),msg));
	}
	
	
	public static synchronized void write(String msg) {
		Date now = Calendar.getInstance().getTime();
		getInstance().writeToLog(FILE_NAME, String.format("%s--%s\r\n", df.format(now),msg));
	}
	
	private void writeToLog(String fileName, String msg) {		
		try {
			if(writer==null){
				writer = new FileWriter(fileName,true);
			}		
			if(writer!=null)
				writer.write(msg);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static synchronized void closeWriter(){
		if(writer!=null){
			try {
				writer.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			writer = null;
		}
	}
}

{'fraction_non_alphanumeric': 0.13769201948295243, 'fraction_numerical': 0.0014986886474334957, 'mean_word_length': 3.683333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5552676', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1713, 'n_words': 399}