<commit_before>/*global window*/
(function (angular, sprintf, vsprintf, moment) {
	'use strict';

	angular.module('logger', []).
	provider('logEnhancer', function() {
		var provider = this;

        this.loggingPattern = '%s - %s: '; // default logging pattern, overwrite in config phase
        this.LEVEL = { TRACE: 4, DEBUG: 3, INFO: 2, WARN: 1, ERROR: 0, OFF: -1 }; // with these configure loglevels in config fase
        this.logLevels = {'*': this.LEVEL.TRACE}; // everything by everyone should be visible by default

		this.$get = function() {
			return {

                // Actually modifies $log. Without calling this in the run phase, $log remains untouched
				enhanceAngularLog : function($log) {
					$log.LEVEL = provider.LEVEL; // assign to $log, so the user can change them after config phase
					$log.logLevels = provider.logLevels; // assign to $log, so the user can change them after config phase

					$log.getInstance = function(context) {
						return {
							trace	: enhanceLogging($log.debug, $log.LEVEL.TRACE, context, provider.loggingPattern),
							debug	: enhanceLogging($log.debug, $log.LEVEL.DEBUG, context, provider.loggingPattern),
							log		: enhanceLogging($log.log, $log.LEVEL.INFO, context, provider.loggingPattern),
							info	: enhanceLogging($log.info, $log.LEVEL.INFO, context, provider.loggingPattern),
							warn	: enhanceLogging($log.warn, $log.LEVEL.WARN, context, provider.loggingPattern),
							error	: enhanceLogging($log.error, $log.LEVEL.ERROR, context, provider.loggingPattern)
						};
					};

					function enhanceLogging(loggingFunc, level, context, loggingPattern) {
						return function() {
                            if (levelPassesThreshold(context, level)) {
                                loggingFunc.apply(null, enhanceLogline(arguments, context, loggingPattern));
                            }
						};

	                    function levelPassesThreshold(context, level) {
	                        return level > $log.LEVEL.OFF && level <= getLogLevelThreshold(context);

	                        function getLogLevelThreshold(context) {
	                        	if (context) {
		                            if ($log.logLevels[context] !== undefined) {
		                                return $log.logLevels[context];
		                            } else if (context.indexOf('.') != -1) {
		                                return getLogLevelThreshold(context.substring(0, context.lastIndexOf('.')));
		                            }
	                        	}
	                        	return $log.logLevels['*'] !== undefined ? $log.logLevels['*'] : $log.LEVEL.TRACE;
	                        }
	                    }

						function enhanceLogline(args, context, loggingPattern) {
	                        var prefix = generatePrefix(context, loggingPattern);
							var processedArgs = maybeApplySprintf([].slice.call(args));
							return [prefix].concat([].slice.call(processedArgs));
							
							function maybeApplySprintf(args) {
								var sprintfCandidate = args.length >= 2 && typeof args[0] === 'string' && args[0].indexOf('%') !== -1;
		                        if (sprintfCandidate) {
		                        	try {
		                        		// count placeholders
			                        	var placeholderCount = 0;
			                        	var f = function() { return placeholderCount++ };
			                        	sprintf(args[0], [f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f]);
			                        	// apply sprintf with the proper arguments
			                        	if (placeholderCount > 0) {
			                        		args[0] = sprintf.apply(null, args);<commit_msg>only check for sprintf candidates if sprintf is actually available<commit_after>/*global window*/
(function (angular, sprintf, vsprintf, moment) {
	'use strict';

	angular.module('logger', []).
	provider('logEnhancer', function() {
		var provider = this;

        this.loggingPattern = '%s - %s: '; // default logging pattern, overwrite in config phase
        this.LEVEL = { TRACE: 4, DEBUG: 3, INFO: 2, WARN: 1, ERROR: 0, OFF: -1 }; // with these configure loglevels in config fase
        this.logLevels = {'*': this.LEVEL.TRACE}; // everything by everyone should be visible by default

		this.$get = function() {
			return {

                // Actually modifies $log. Without calling this in the run phase, $log remains untouched
				enhanceAngularLog : function($log) {
					$log.LEVEL = provider.LEVEL; // assign to $log, so the user can change them after config phase
					$log.logLevels = provider.logLevels; // assign to $log, so the user can change them after config phase

					$log.getInstance = function(context) {
						return {
							trace	: enhanceLogging($log.debug, $log.LEVEL.TRACE, context, provider.loggingPattern),
							debug	: enhanceLogging($log.debug, $log.LEVEL.DEBUG, context, provider.loggingPattern),
							log		: enhanceLogging($log.log, $log.LEVEL.INFO, context, provider.loggingPattern),
							info	: enhanceLogging($log.info, $log.LEVEL.INFO, context, provider.loggingPattern),
							warn	: enhanceLogging($log.warn, $log.LEVEL.WARN, context, provider.loggingPattern),
							error	: enhanceLogging($log.error, $log.LEVEL.ERROR, context, provider.loggingPattern)
						};
					};

					function enhanceLogging(loggingFunc, level, context, loggingPattern) {
						return function() {
                            if (levelPassesThreshold(context, level)) {
                                loggingFunc.apply(null, enhanceLogline(arguments, context, loggingPattern));
                            }
						};

	                    function levelPassesThreshold(context, level) {
	                        return level > $log.LEVEL.OFF && level <= getLogLevelThreshold(context);

	                        function getLogLevelThreshold(context) {
	                        	if (context) {
		                            if ($log.logLevels[context] !== undefined) {
		                                return $log.logLevels[context];
		                            } else if (context.indexOf('.') != -1) {
		                                return getLogLevelThreshold(context.substring(0, context.lastIndexOf('.')));
		                            }
	                        	}
	                        	return $log.logLevels['*'] !== undefined ? $log.logLevels['*'] : $log.LEVEL.TRACE;
	                        }
	                    }

						function enhanceLogline(args, context, loggingPattern) {
	                        var prefix = generatePrefix(context, loggingPattern);
							var processedArgs = maybeApplySprintf([].slice.call(args));
							return [prefix].concat([].slice.call(processedArgs));
							
							function maybeApplySprintf(args) {
								var sprintfCandidate = sprintf && args.length >= 2 && typeof args[0] === 'string' && args[0].indexOf('%') !== -1;
		                        if (sprintfCandidate) {
		                        	try {
		                        		// count placeholders
			                        	var placeholderCount = 0;
			                        	var f = function() { return placeholderCount++ };
			                        	sprintf(args[0], f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f);
			                        	// apply sprintf with the proper arguments
			                        	if (placeholderCount > 0) {
			                        		args[0] = sprintf.apply(null, args);
{'fraction_non_alphanumeric': 0.11974283418162336, 'fraction_numerical': 0.004286096972944013, 'mean_word_length': 1.8521772345301757, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6459205', 'n_tokens_mistral': 2311, 'n_tokens_neox': 1901, 'n_words': 465}