1 | import "core-js/modules/es.array.concat.js";
|
2 | import "core-js/modules/es.array.iterator.js";
|
3 | import "core-js/modules/es.object.to-string.js";
|
4 | import "core-js/modules/es.set.js";
|
5 | import "core-js/modules/es.string.iterator.js";
|
6 | import "core-js/modules/web.dom-collections.iterator.js";
|
7 | import "core-js/modules/es.regexp.exec.js";
|
8 | import "core-js/modules/es.string.replace.js";
|
9 | import global from 'global';
|
10 | var LOGLEVEL = global.LOGLEVEL,
|
11 | console = global.console;
|
12 | var levels = {
|
13 | trace: 1,
|
14 | debug: 2,
|
15 | info: 3,
|
16 | warn: 4,
|
17 | error: 5,
|
18 | silent: 10
|
19 | };
|
20 | var currentLogLevelString = LOGLEVEL;
|
21 | var currentLogLevelNumber = levels[currentLogLevelString] || levels.info;
|
22 | export 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 | };
|
66 | var logged = new Set();
|
67 | export 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 |
|
80 | once.clear = function () {
|
81 | return logged.clear();
|
82 | };
|
83 |
|
84 | once.trace = once('trace');
|
85 | once.debug = once('debug');
|
86 | once.info = once('info');
|
87 | once.warn = once('warn');
|
88 | once.error = once('error');
|
89 | once.log = once('log');
|
90 | export 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'));
|
103 |
|
104 | while (reResultArray = startTagRe.exec(args[0])) {
|
105 | argArray.push(reResultArray[2]);
|
106 | argArray.push('');
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 | for (var j = 1; j < args.length; j++) {
|
112 | argArray.push(args[j]);
|
113 | }
|
114 | }
|
115 |
|
116 |
|
117 | logger[type].apply(logger, argArray);
|
118 | };
|
119 | };
|
120 | pretty.trace = pretty('trace');
|
121 | pretty.debug = pretty('debug');
|
122 | pretty.info = pretty('info');
|
123 | pretty.warn = pretty('warn');
|
124 | pretty.error = pretty('error'); |
\ | No newline at end of file |