<commit_before>/*
 * $Log: StatisticsKeeperLogger.java,v $
 * Revision 1.6  2008-09-04 12:19:05  europe\L190409
 * log to daily rolling file
 *
 * Revision 1.5  2008/07/24 12:24:12  <NAME> <<EMAIL>>
 * log statistics as XML
 *
 * Revision 1.4  2008/05/14 09:30:43  <NAME> <<EMAIL>>
 * simplified methodnames of StatisticsKeeperIterationHandler
 *
 * Revision 1.3  2007/02/12 14:12:03  <NAME> <<EMAIL>>
 * Logger from LogUtil
 *
 * Revision 1.2  2006/02/09 08:02:46  <NAME> <<EMAIL>>
 * iterate over string scalars too
 *
 * Revision 1.1  2005/12/28 08:31:33  <NAME> <<EMAIL>>
 * introduced StatisticsKeeper-iteration
 *
 */
package nl.nn.adapterframework.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import org.apache.log4j.Logger;

/**
 * Logs statistics-keeper contents to log.
 * 
 * @author  <NAME>
 * @since   4.4.3
 * @version Id
 */
public class StatisticsKeeperLogger extends StatisticsKeeperXmlBuilder {
	protected Logger log = LogUtil.getLogger("nl.nn.adapterframework.statistics");

	public StatisticsKeeperLogger(Date now, Date mark) {
		super(now,mark);
	}

	public void end(Object data) {
		super.end(data);

		AppConstants ac = AppConstants.getInstance();		
		String directory = ac.getResolvedProperty("log.dir");
		int retentionDays=ac.getInt("statistics.retention",7);
		String filenamePattern=ac.getResolvedProperty("instance.name")+"-stats_";
		String extension=".log";
		File outfile=FileUtils.getDailyRollingFile(directory, filenamePattern, extension, retentionDays);

		FileWriter fw=null;
		try {
			fw = new FileWriter(outfile,true);
			fw.write(getXml().toXML());
			fw.write("\n");
		} catch (IOException e) {
			log.error("Could not write statistics to file ["+outfile.getPath()+"]",e);
		} finally {
			if (fw!=null) {<commit_msg>made statisticsfile weekly rolling<commit_after>/*
 * $Log: StatisticsKeeperLogger.java,v $
 * Revision 1.7  2009-01-08 16:41:31  L190409
 * made statisticsfile weekly rolling
 *
 * Revision 1.6  2008/09/04 12:19:05  <NAME> <<EMAIL>>
 * log to daily rolling file
 *
 * Revision 1.5  2008/07/24 12:24:12  <NAME> <<EMAIL>>
 * log statistics as XML
 *
 * Revision 1.4  2008/05/14 09:30:43  <NAME> <<EMAIL>>
 * simplified methodnames of StatisticsKeeperIterationHandler
 *
 * Revision 1.3  2007/02/12 14:12:03  <NAME> <<EMAIL>>
 * Logger from LogUtil
 *
 * Revision 1.2  2006/02/09 08:02:46  <NAME> <<EMAIL>>
 * iterate over string scalars too
 *
 * Revision 1.1  2005/12/28 08:31:33  <NAME> <<EMAIL>>
 * introduced StatisticsKeeper-iteration
 *
 */
package nl.nn.adapterframework.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import org.apache.log4j.Logger;

/**
 * Logs statistics-keeper contents to log.
 * 
 * @author  <NAME>
 * @since   4.4.3
 * @version Id
 */
public class StatisticsKeeperLogger extends StatisticsKeeperXmlBuilder {
	protected Logger log = LogUtil.getLogger("nl.nn.adapterframework.statistics");

	public StatisticsKeeperLogger(Date now, Date mark) {
		super(now,mark);
	}

	public void end(Object data) {
		super.end(data);

		AppConstants ac = AppConstants.getInstance();		
		String directory = ac.getResolvedProperty("log.dir");
		int retentionDays=ac.getInt("statistics.retention",7);
		String filenamePattern=ac.getResolvedProperty("instance.name")+"-stats_";
		String extension=".log";
		File outfile=FileUtils.getWeeklyRollingFile(directory, filenamePattern, extension, retentionDays);

		FileWriter fw=null;
		try {
			fw = new FileWriter(outfile,true);
			fw.write(getXml().toXML());
			fw.write("\n");
		} catch (IOException e) {
			log.error("Could not write statistics to file ["+outfile.getPath()+"]",e);
		} finally {
			if (fw!=null) {
{'fraction_non_alphanumeric': 0.14049586776859505, 'fraction_numerical': 0.061316982138096505, 'mean_word_length': 4.314447592067989, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, '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': '3750579', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1267, 'n_words': 297}