<commit_before>'use strict';

const _ = require('lodash');
const chalk = require('chalk');

const EventsBus = require('./EventsBus');

class Logger {
    constructor(prefix) {
        let onEvent = this.onEvent.bind(this);

        this._prefix = '';

        EventsBus.listen('**', function (data) {
            onEvent(this.event, data);
        });
    }
    onEvent(event, payload) {
        let prefix = this._prefix;
        let output = '';

        // If we get a string through,
        // attempt to parse it to json
        if (typeof payload === 'string') {
            try { payload = JSON.parse(payload) } catch (err) {}
        }

        if (typeof payload.name !== 'undefined') {
            prefix += chalk.green(`[${payload.name}]`)
        }

        if (typeof event !== 'undefined') {
            prefix += chalk.yellow(`[${event}]`);
        }

        if (typeof payload.data === 'string' && event.indexOf('data:') === -1 ) {
            output += payload.data;
        }

        if (event.indexOf(':error') !== -1) {
            output += this.stringify(payload.data);
        }

        if (event.indexOf('data:') === 0) {
            output += this.stringify(payload);
        }

        if (event.indexOf('syrup:started') === 0) {
            output += this.stringify(payload);
        }

        console.log(`${prefix} ${output}`);
    }
    stringify(data) {
        try {
            if (typeof data === 'object') {
                let _data = {};
                _.each(data, (value, key) => {
                    if (key.indexOf('_') !== 0) {
                        _data[key] = value;
                    }
                });

                data = JSON.stringify(_data);
            }
        } catch (err) {

        }

        return (typeof data === 'undefined') ? '' : data;
    }
}

module.exports = Logger;<commit_msg>Clean up logger<commit_after>'use strict';

const _ = require('lodash');
const chalk = require('chalk');

const EventsBus = require('./EventsBus');

class Logger {
    constructor() {
        let onEvent = this.onEvent.bind(this);

        this._prefix = '';

        EventsBus.listen('**', function (data) {
            onEvent(this.event, data);
        });
    }
    onEvent(event, payload) {
        let prefix = this._prefix;
        let output = '';

        // If we get a string through,
        // attempt to parse it to json
        if (typeof payload === 'string') {
            try { payload = JSON.parse(payload); } catch (err) {}
        }

        if (typeof payload.name !== 'undefined') {
            prefix += chalk.green(`[${payload.name}]`);
        }

        if (typeof event !== 'undefined') {
            prefix += chalk.yellow(`[${event}]`);
        }

        if (typeof payload.data === 'string' && event.indexOf('data:') === -1 ) {
            output += payload.data;
        }

        if (event.indexOf(':error') !== -1) {
            output += this.stringify(payload.data);
        }

        if (event.indexOf('data:') === 0) {
            output += this.stringify(payload);
        }

        if (event.indexOf('syrup:started') === 0) {
            output += this.stringify(payload);
        }

        console.log(`${prefix} ${output}`);
    }
    stringify(data) {
        try {
            if (typeof data === 'object') {
                let _data = {};
                _.each(data, (value, key) => {
                    if (key.indexOf('_') !== 0) {
                        _data[key] = value;
                    }
                });

                data = JSON.stringify(_data);
            }
        } catch (err) {

        }

        return (typeof data === 'undefined') ? '' : data;
    }
}

module.exports = Logger;
{'fraction_non_alphanumeric': 0.16702470461868957, 'fraction_numerical': 0.0026852846401718583, 'mean_word_length': 1.546138072453862, 'pattern_counts': {'":': 0, '<': 3, '<?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': '67894', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1018, 'n_words': 229}