All files / lib/loggers BrowserConsoleLogger.js

0% Statements 0/10
0% Branches 0/4
0% Functions 0/4
0% Lines 0/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                                                           
'use strict';
 
module.exports = function inject(logConfig) {
    logConfig = logConfig || {};
    const extend = require('object-util').extend;
    const theme = extend(require('../conf/themes'), logConfig.theme || {});
    const methodNames = [
        'log', 'error', 'warn', 'info', 'assert', 'debug'
    ];
 
    /**
     * Logger that sends messages to the browser console.
     *
     * @class
     * @implements {Logger}
     */
    function BrowserConsoleLogger() {
    }
 
    methodNames.forEach(name => {
        BrowserConsoleLogger.prototype[name] = function (...varargs) {
            let args = ['%c%s', `color: ${theme[name]}`, ...varargs];
            console[name](...args);
        }
    });
 
    return BrowserConsoleLogger;
};