<commit_before>package org.springframework.roo.addon.logging;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.metadata.MetadataService;
import org.springframework.roo.model.JavaPackage;
import org.springframework.roo.process.manager.FileManager;
import org.springframework.roo.process.manager.MutableFile;
import org.springframework.roo.project.Path;
import org.springframework.roo.project.PathResolver;
import org.springframework.roo.project.ProjectMetadata;
import org.springframework.roo.support.util.Assert;
import org.springframework.roo.support.util.TemplateUtils;

/**
 * Provides logging configuration operations.
 *
 * @author <NAME>
 * @since 1.0
 */
@Component
@Service
public class LoggingOperationsImpl implements LoggingOperations {
	
	@Reference private FileManager fileManager;
	@Reference private PathResolver pathResolver;
	@Reference private MetadataService metadataService;	
	
	public boolean isConfigureLoggingAvailable() {
		return metadataService.get(ProjectMetadata.getProjectIdentifier()) != null;
	}
	
	public void configureLogging(LogLevel logLevel, LoggerPackage loggerPackage) {
		Assert.notNull(logLevel, "LogLevel required");
		Assert.notNull(loggerPackage, "LoggerPackage required");
		
		setupProperties(logLevel, loggerPackage);
//		setupWebXml();
	}
	
	private void setupProperties(LogLevel logLevel, LoggerPackage loggerPackage) {
		String filePath = pathResolver.getIdentifier(Path.SRC_MAIN_RESOURCES, "log4j.properties");
		MutableFile log4jMutableFile = null;
		Properties props = new Properties();
		
		try {
			if (fileManager.exists(filePath)) {
				log4jMutableFile = fileManager.updateFile(filePath);
				props.load(log4jMutableFile.getInputStream());
			} else {
				log4jMutableFile = fileManager.createFile(filePath);
				InputStream templateInputStream = TemplateUtils.getTemplate(getClass(), "log4j-template.properties");
				Assert.notNull(templateInputStream, "Could not acquire log4j configuration template");
				props.load(templateInputStream);
			}
		} catch (IOException ioe) {
			throw new IllegalStateException(ioe);
		}

		ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
		Assert.notNull(projectMetadata, "Project metadata is unavailable");
		JavaPackage topLevelPackage = projectMetadata.getTopLevelPackage();
		
		for (String packageName : loggerPackage.getPackageNames()) {
			if (LoggerPackage.ROOT.equals(loggerPackage)) {
				props.remove("log4j.rootLogger");
				props.setProperty("log4j.rootLogger", logLevel.getKey() + ", stdout, R");
			} else {						
				packageName = packageName.equals("TO_BE_CHANGED_BY_LISTENER") ? topLevelPackage.getFullyQualifiedPackageName() : packageName;
				props.remove("log4j.logger." + packageName);
				props.setProperty("log4j.logger." + packageName, logLevel.getKey());
			}
		}
		
		try {
			props.store(log4jMutableFile.getOutputStream(), "Updated at " + new Date());
		} catch (IOException ioe) {
			throw new IllegalStateException(ioe);
		}
	}
}
<commit_msg>OPEN - issue ROO-146: Add addon to deploy and run Roo projects on Google App Engine infrastructure  http://jira.springframework.org/browse/ROO-146 Removed rolling file appender from root logger<commit_after>package org.springframework.roo.addon.logging;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.metadata.MetadataService;
import org.springframework.roo.model.JavaPackage;
import org.springframework.roo.process.manager.FileManager;
import org.springframework.roo.process.manager.MutableFile;
import org.springframework.roo.project.Path;
import org.springframework.roo.project.PathResolver;
import org.springframework.roo.project.ProjectMetadata;
import org.springframework.roo.support.util.Assert;
import org.springframework.roo.support.util.TemplateUtils;

/**
 * Provides logging configuration operations.
 *
 * @author <NAME>
 * @since 1.0
 */
@Component
@Service
public class LoggingOperationsImpl implements LoggingOperations {
	
	@Reference private FileManager fileManager;
	@Reference private PathResolver pathResolver;
	@Reference private MetadataService metadataService;	
	
	public boolean isConfigureLoggingAvailable() {
		return metadataService.get(ProjectMetadata.getProjectIdentifier()) != null;
	}
	
	public void configureLogging(LogLevel logLevel, LoggerPackage loggerPackage) {
		Assert.notNull(logLevel, "LogLevel required");
		Assert.notNull(loggerPackage, "LoggerPackage required");
		
		setupProperties(logLevel, loggerPackage);
		// setupWebXml();
	}
	
	private void setupProperties(LogLevel logLevel, LoggerPackage loggerPackage) {
		String filePath = pathResolver.getIdentifier(Path.SRC_MAIN_RESOURCES, "log4j.properties");
		MutableFile log4jMutableFile = null;
		Properties props = new Properties();
		
		try {
			if (fileManager.exists(filePath)) {
				log4jMutableFile = fileManager.updateFile(filePath);
				props.load(log4jMutableFile.getInputStream());
			} else {
				log4jMutableFile = fileManager.createFile(filePath);
				InputStream templateInputStream = TemplateUtils.getTemplate(getClass(), "log4j-template.properties");
				Assert.notNull(templateInputStream, "Could not acquire log4j configuration template");
				props.load(templateInputStream);
			}
		} catch (IOException ioe) {
			throw new IllegalStateException(ioe);
		}

		ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
		Assert.notNull(projectMetadata, "Project metadata is unavailable");
		JavaPackage topLevelPackage = projectMetadata.getTopLevelPackage();
		
		for (String packageName : loggerPackage.getPackageNames()) {
			if (LoggerPackage.ROOT.equals(loggerPackage)) {
				props.remove("log4j.rootLogger");
				props.setProperty("log4j.rootLogger", logLevel.getKey() + ", stdout");
			} else {						
				packageName = packageName.equals("TO_BE_CHANGED_BY_LISTENER") ? topLevelPackage.getFullyQualifiedPackageName() : packageName;
				props.remove("log4j.logger." + packageName);
				props.setProperty("log4j.logger." + packageName, logLevel.getKey());
			}
		}
		
		try {
			props.store(log4jMutableFile.getOutputStream(), "Updated at " + new Date());
		} catch (IOException ioe) {
			throw new IllegalStateException(ioe);
		}
	}
}

{'fraction_non_alphanumeric': 0.10585786500148676, 'fraction_numerical': 0.005055010407374368, 'mean_word_length': 5.6406712734452125, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3755884', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1861, 'n_words': 364}