<commit_before>/*
 * mhLog
 *
 * Description: A simple utility to control log output.  You can optionally display
 * an abbreviated call stack to better understand the location of the message.
 *
 * @author mhaungs
 */

	/*jshint globalstrict: true*/
    "use strict";  // EMCAScript 5 pragma to catch more javascript errors

    /*
     ************ Module Variables *************
     */

    // Log level enumeration
    var LEVEL = {
        ALL: 0,
        DEBUG: 1,
        DEVELOPMENT: 2,
        PRODUCTION: 3
    };

    var currentLevel = LEVEL.PRODUCTION;
    var strace = false; // Boolean that toggles displaying a stack trace

    /*
     ************ Initialization methods *************
     */

    /*
     ************ Public methods *************
     */
    function setShowStackTrace(val) {
        if (typeof val === 'boolean') {
            strace = val;
        }
    }

    function setLoggingLevel(level) {
        if (levelValid(level)) {
            currentLevel = level;
        }
    }

    function log(level, msg) {
        if (levelValid(level)) {
            if (level >= currentLevel) {
                if (strace === true)
                    logCallTrace();
                console.log("mhlog: Message: " + msg);
                return msg;
            }
        }
        return null;
    }

    /*
     ************ Private methods *************
     */

    function levelValid(level) {
        return (level <= LEVEL.PRODUCTION && level >= LEVEL.ALL);
    }

    // Works in Safari, Chrome, and FireFox
    function logCallTrace() {
        var stackArray, i = 0, entry, results = [];

        try {
            throw new Error("mhLog");
        }
        catch (e) {
            if (e.stack) {
                stackArray = e.stack.split('\n');
                entry = stackArray.shift(); // get rid of reference to this function (logCallTrace)
                while (stackArray.length > 0 && i < 4) {
                    entry = stackArray.shift();  // get one level of call stack
                    results.push(entry.slice(0, entry.indexOf('@')) // keep everything up to @ symbol (Safari)
                            .replace(/^\s+|\s+$/g, '') // Trim whitespaces (Chrome)
                            .replace(/\(http.*$/g, '')); // Remove http reference (Chrome)
                    i++;
                }
                console.log("mhLog: Call Trace: " + results.join(", "));
            }
        }
    }

    /*
     ************ Exports *************
     */

	/* global exports: true */
    exports.LEVEL = LEVEL;
    exports.setShowStackTrace = setShowStackTrace;
    exports.setLoggingLevel = setLoggingLevel;
    exports.log = log;
<commit_msg>Changed to accomodate my new module template.<commit_after>/*
 * mhLog
 *
 * Description: A simple utility to control log output.  You can optionally display
 * an abbreviated call stack to better understand the location of the message.
 *
 * @author mhaungs
 */

/* global exports: true */
module.exports = function() {

    /*jshint globalstrict: true*/
    "use strict";  // EMCAScript 5 pragma to catch more javascript errors

    /*
     ************ Module Variables *************
     */

    // Log level enumeration
    var LEVEL = {
        ALL: 0,
        DEBUG: 1,
        DEVELOPMENT: 2,
        PRODUCTION: 3
    };

    var currentLevel = LEVEL.PRODUCTION;
    var strace = false; // Boolean that toggles displaying a stack trace

    /*
     ************ Initialization methods *************
     */

    /*
     ************ Public methods *************
     */
    function setShowStackTrace(val) {
        if (typeof val === 'boolean') {
            strace = val;
        }
    }

    function setLoggingLevel(level) {
        if (levelValid(level)) {
            currentLevel = level;
        }
    }

    function log(level, msg) {
        if (levelValid(level)) {
            if (level >= currentLevel) {
                if (strace === true)
                    logCallTrace();
                console.log("mhlog: Message: " + msg);
                return msg;
            }
        }
        return null;
    }

    /*
     ************ Private methods *************
     */

    function levelValid(level) {
        return (level <= LEVEL.PRODUCTION && level >= LEVEL.ALL);
    }

    // Works in Safari, Chrome, and FireFox
    function logCallTrace() {
        var stackArray, i = 0, entry, results = [];

        try {
            throw new Error("mhLog");
        }
        catch (e) {
            if (e.stack) {
                stackArray = e.stack.split('\n');
                entry = stackArray.shift(); // get rid of reference to this function (logCallTrace)
                while (stackArray.length > 0 && i < 4) {
                    entry = stackArray.shift();  // get one level of call stack
                    results.push(entry.slice(0, entry.indexOf('@')) // keep everything up to @ symbol (Safari)
                            .replace(/^\s+|\s+$/g, '') // Trim whitespaces (Chrome)
                            .replace(/\(http.*$/g, '')); // Remove http reference (Chrome)
                    i++;
                }
                console.log("mhLog: Call Trace: " + results.join(", "));
            }
        }
    }

    /*
     ************ Exports *************
     */

    return {
        LEVEL: LEVEL,
        setShowStackTrace: setShowStackTrace,
        setLoggingLevel: setLoggingLevel,
        log: log
    };

};
{'fraction_non_alphanumeric': 0.15694164989939638, 'fraction_numerical': 0.0032924821657216025, 'mean_word_length': 1.6238003838771593, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5839465', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1466, 'n_words': 401}