<commit_before>package com.github.aureliano.damihilogs.writer;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import org.apache.log4j.Logger;

import com.github.aureliano.damihilogs.config.output.FileOutputConfig;
import com.github.aureliano.damihilogs.exception.DaMihiLogsException;
import com.github.aureliano.damihilogs.formatter.PlainTextFormatter;

public class FileDataWriter extends AbstractDataWriter {
	
	private PrintWriter writer;
	
	private static final Logger logger = Logger.getLogger(FileDataWriter.class);
	
	public FileDataWriter() {
		super();
	}

	@Override
	public void write(String content) {
		this.initialize();
		
		Object data = super.getParser().parse(content);
		super.executeBeforeWritingMethodListeners(data);
		if (data == null) {
			return;
		}

		boolean accept = super.getFilter().accept(data);
		if (accept) {
			String text = super.outputFormatter.format(data);
			this.writer.println(text);
		}
		
		super.executeAfterWritingMethodListeners(data, accept);
	}
	
	@Override
	public void endResources() {
		if (this.writer == null) {
			return;
		}
		
		logger.info(" >>> Flushing and closing stream writer.");
		
		this.writer.flush();
		this.writer.close();		
	}
	
	private void initialize() {
		if (this.writer != null) {
			return;
		}
		
		if (super.outputFormatter == null) {
			super.outputFormatter = new PlainTextFormatter();
		}
		
		FileOutputConfig fileOutputConfiguration = (FileOutputConfig) super.outputConfiguration;
		
		logger.info("Outputing data to " + fileOutputConfiguration.getFile().getPath());
		logger.info("Data encondig: " + fileOutputConfiguration.getEncoding());
		logger.info("Append data to file? " + fileOutputConfiguration.isAppend());
		
		try {
			FileOutputStream stream = new FileOutputStream(fileOutputConfiguration.getFile(), fileOutputConfiguration.isAppend());
			BufferedOutputStream buffer = new BufferedOutputStream(stream);
			OutputStreamWriter osw = new OutputStreamWriter(buffer, fileOutputConfiguration.getEncoding());
			this.writer = new PrintWriter(osw);
		} catch (IOException ex) {
			throw new DaMihiLogsException(ex);
		}
	}
}<commit_msg>Change log level.<commit_after>package com.github.aureliano.damihilogs.writer;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import org.apache.log4j.Logger;

import com.github.aureliano.damihilogs.config.output.FileOutputConfig;
import com.github.aureliano.damihilogs.exception.DaMihiLogsException;
import com.github.aureliano.damihilogs.formatter.PlainTextFormatter;

public class FileDataWriter extends AbstractDataWriter {
	
	private PrintWriter writer;
	
	private static final Logger logger = Logger.getLogger(FileDataWriter.class);
	
	public FileDataWriter() {
		super();
	}

	@Override
	public void write(String content) {
		this.initialize();
		
		Object data = super.getParser().parse(content);
		super.executeBeforeWritingMethodListeners(data);
		if (data == null) {
			return;
		}

		boolean accept = super.getFilter().accept(data);
		if (accept) {
			String text = super.outputFormatter.format(data);
			this.writer.println(text);
		}
		
		super.executeAfterWritingMethodListeners(data, accept);
	}
	
	@Override
	public void endResources() {
		if (this.writer == null) {
			return;
		}
		
		logger.debug(" >>> Flushing and closing stream writer.");
		
		this.writer.flush();
		this.writer.close();		
	}
	
	private void initialize() {
		if (this.writer != null) {
			return;
		}
		
		if (super.outputFormatter == null) {
			super.outputFormatter = new PlainTextFormatter();
		}
		
		FileOutputConfig fileOutputConfiguration = (FileOutputConfig) super.outputConfiguration;
		
		logger.info("Outputing data to " + fileOutputConfiguration.getFile().getPath());
		logger.debug("Data encondig: " + fileOutputConfiguration.getEncoding());
		logger.debug("Append data to file? " + fileOutputConfiguration.isAppend());
		
		try {
			FileOutputStream stream = new FileOutputStream(fileOutputConfiguration.getFile(), fileOutputConfiguration.isAppend());
			BufferedOutputStream buffer = new BufferedOutputStream(stream);
			OutputStreamWriter osw = new OutputStreamWriter(buffer, fileOutputConfiguration.getEncoding());
			this.writer = new PrintWriter(osw);
		} catch (IOException ex) {
			throw new DaMihiLogsException(ex);
		}
	}
}
{'fraction_non_alphanumeric': 0.11234705228031146, 'fraction_numerical': 0.0004449388209121246, 'mean_word_length': 4.854166666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3752604', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1277, 'n_words': 264}