UNPKG

4.4 kBJavaScriptView Raw
1import "core-js/modules/es.array.concat.js";
2import "core-js/modules/es.array.iterator.js";
3import "core-js/modules/es.object.to-string.js";
4import "core-js/modules/es.set.js";
5import "core-js/modules/es.string.iterator.js";
6import "core-js/modules/web.dom-collections.iterator.js";
7import "core-js/modules/es.regexp.exec.js";
8import "core-js/modules/es.string.replace.js";
9import global from 'global';
10var LOGLEVEL = global.LOGLEVEL,
11 console = global.console;
12var levels = {
13 trace: 1,
14 debug: 2,
15 info: 3,
16 warn: 4,
17 error: 5,
18 silent: 10
19};
20var currentLogLevelString = LOGLEVEL;
21var currentLogLevelNumber = levels[currentLogLevelString] || levels.info;
22export var logger = {
23 trace: function trace(message) {
24 for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
25 rest[_key - 1] = arguments[_key];
26 }
27
28 return currentLogLevelNumber <= levels.trace && console.trace.apply(console, [message].concat(rest));
29 },
30 debug: function debug(message) {
31 for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
32 rest[_key2 - 1] = arguments[_key2];
33 }
34
35 return currentLogLevelNumber <= levels.debug && console.debug.apply(console, [message].concat(rest));
36 },
37 info: function info(message) {
38 for (var _len3 = arguments.length, rest = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
39 rest[_key3 - 1] = arguments[_key3];
40 }
41
42 return currentLogLevelNumber <= levels.info && console.info.apply(console, [message].concat(rest));
43 },
44 warn: function warn(message) {
45 for (var _len4 = arguments.length, rest = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
46 rest[_key4 - 1] = arguments[_key4];
47 }
48
49 return currentLogLevelNumber <= levels.warn && console.warn.apply(console, [message].concat(rest));
50 },
51 error: function error(message) {
52 for (var _len5 = arguments.length, rest = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
53 rest[_key5 - 1] = arguments[_key5];
54 }
55
56 return currentLogLevelNumber <= levels.error && console.error.apply(console, [message].concat(rest));
57 },
58 log: function log(message) {
59 for (var _len6 = arguments.length, rest = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
60 rest[_key6 - 1] = arguments[_key6];
61 }
62
63 return currentLogLevelNumber < levels.silent && console.log.apply(console, [message].concat(rest));
64 }
65};
66var logged = new Set();
67export var once = function once(type) {
68 return function (message) {
69 if (logged.has(message)) return undefined;
70 logged.add(message);
71
72 for (var _len7 = arguments.length, rest = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
73 rest[_key7 - 1] = arguments[_key7];
74 }
75
76 return logger[type].apply(logger, [message].concat(rest));
77 };
78};
79
80once.clear = function () {
81 return logged.clear();
82};
83
84once.trace = once('trace');
85once.debug = once('debug');
86once.info = once('info');
87once.warn = once('warn');
88once.error = once('error');
89once.log = once('log');
90export var pretty = function pretty(type) {
91 return function () {
92 var argArray = [];
93
94 for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
95 args[_key8] = arguments[_key8];
96 }
97
98 if (args.length) {
99 var startTagRe = /<span\s+style=(['"])([^'"]*)\1\s*>/gi;
100 var endTagRe = /<\/span>/gi;
101 var reResultArray;
102 argArray.push(args[0].replace(startTagRe, '%c').replace(endTagRe, '%c')); // eslint-disable-next-line no-cond-assign
103
104 while (reResultArray = startTagRe.exec(args[0])) {
105 argArray.push(reResultArray[2]);
106 argArray.push('');
107 } // pass through subsequent args since chrome dev tools does not (yet) support console.log styling of the following form: console.log('%cBlue!', 'color: blue;', '%cRed!', 'color: red;');
108 // eslint-disable-next-line no-plusplus
109
110
111 for (var j = 1; j < args.length; j++) {
112 argArray.push(args[j]);
113 }
114 } // eslint-disable-next-line prefer-spread
115
116
117 logger[type].apply(logger, argArray);
118 };
119};
120pretty.trace = pretty('trace');
121pretty.debug = pretty('debug');
122pretty.info = pretty('info');
123pretty.warn = pretty('warn');
124pretty.error = pretty('error');
\No newline at end of file