<commit_before>/**
 * Author: <NAME>
 * Date: 2/16/15
 *
 * Listens for log events and sends them to the console
 */
angular.module('pancakesAngular').factory('clientLogReactor',
    function (_, extlibs, eventBus, config, stateHelper, activeUser, storage) {

        config = config || {};

        var raven = extlibs.get('Raven');
        var useConsole = config.logTransport && config.logTransport.indexOf('console') >= 0;
        var useRemote = raven && config.logTransport && config.logTransport.indexOf('remote') >= 0;
        var logLevel = config.logLevel || 'error';

        if (raven && raven.config) {
            raven.config(config.errorUrl, {}).install();
        }

        /* eslint no-console:0 */

        /**
         * Send log to the console
         * @param event
         * @param logData
         */
        function log(event, logData) {
            if (useConsole) {
                console.log(logData);
            }

            if (useRemote) {
                var err = logData.err;
                delete logData.err;

                if (angular.isString(logData)) {
                    var msg = logData;
                    logData = {};
                    logData.msg = msg;
                }

                logData.url = stateHelper.getCurrentUrl();
                logData.userId = activeUser._id;
                logData.username = activeUser.username;
                logData.lastApiCall = storage.get('lastApiCall');

                err ?
                    raven.captureException(err, { extra: logData }) :
                    logData.msg ?
                        raven.captureMessage(logData.msg, { extra: logData }) :
                        raven.captureMessage(JSON.stringify(logData), { extra: logData });
<commit_msg>No logging if no data<commit_after>/**
 * Author: <NAME>
 * Date: 2/16/15
 *
 * Listens for log events and sends them to the console
 */
angular.module('pancakesAngular').factory('clientLogReactor',
    function (_, extlibs, eventBus, config, stateHelper, activeUser, storage) {

        config = config || {};

        var raven = extlibs.get('Raven');
        var useConsole = config.logTransport && config.logTransport.indexOf('console') >= 0;
        var useRemote = raven && config.logTransport && config.logTransport.indexOf('remote') >= 0;
        var logLevel = config.logLevel || 'error';

        if (raven && raven.config) {
            raven.config(config.errorUrl, {}).install();
        }

        /* eslint no-console:0 */

        /**
         * Send log to the console
         * @param event
         * @param logData
         */
        function log(event, logData) {
            if (useConsole) {
                console.log(logData);
            }

            if (useRemote) {
                var err = logData.err;
                delete logData.err;

                if (!logData) {
                    return;
                }

                if (angular.isString(logData)) {
                    var msg = logData;
                    logData = {};
                    logData.msg = msg;
                }

                logData.url = stateHelper.getCurrentUrl();
                logData.userId = activeUser._id;
                logData.username = activeUser.username;
                logData.lastApiCall = storage.get('lastApiCall');

                err ?
                    raven.captureException(err, { extra: logData }) :
                    logData.msg ?
                        raven.captureMessage(logData.msg, { extra: logData }) :
                        raven.captureMessage(JSON.stringify(logData), { extra: logData });

{'fraction_non_alphanumeric': 0.1160296948034094, 'fraction_numerical': 0.004399230134726423, 'mean_word_length': 1.535191637630662, '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': '5372472', 'n_tokens_mistral': 1002, 'n_tokens_neox': 935, 'n_words': 205}