1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const chalk = require('chalk');
|
12 | const loglevel = require('loglevelnext');
|
13 |
|
14 | const symbols = { ok: '⬡', whoops: '⬢' };
|
15 | const colors = {
|
16 | trace: 'cyan',
|
17 | debug: 'magenta',
|
18 | info: 'blue',
|
19 | warn: 'yellow',
|
20 | error: 'red'
|
21 | };
|
22 |
|
23 |
|
24 | const forceError = (...args) => {
|
25 | const { error } = console;
|
26 | error(chalk.red(`${symbols.whoops} wps:`), ...args);
|
27 | };
|
28 |
|
29 | const getLogger = (options) => {
|
30 | const prefix = {
|
31 | level: ({ level }) => {
|
32 | const color = colors[level];
|
33 |
|
34 | const symbol = ['error', 'warn'].includes(level) ? symbols.whoops : symbols.ok;
|
35 | return chalk[color](`${symbol} wps: `);
|
36 | },
|
37 | template: '{{level}}'
|
38 | };
|
39 |
|
40 |
|
41 | if (options.timestamp) {
|
42 | prefix.template = `[{{time}}] ${prefix.template}`;
|
43 | }
|
44 |
|
45 |
|
46 | options.prefix = prefix;
|
47 | options.name = 'webpack-plugin-serve';
|
48 |
|
49 | const log = loglevel.create(options);
|
50 |
|
51 | return log;
|
52 | };
|
53 |
|
54 | module.exports = { forceError, getLogger };
|