source: trip-planner-front/node_modules/webpack-log/src/index.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3/* global window: true */
4/* eslint-disable
5 no-shadow,
6 no-param-reassign,
7 space-before-function-paren
8*/
9const uuid = require('uuid/v4');
10const colors = require('ansi-colors');
11const loglevel = require('./loglevel');
12
13const symbols = {
14 trace: colors.grey('₸'),
15 debug: colors.cyan('➤'),
16 info: colors.blue(colors.symbols.info),
17 warn: colors.yellow(colors.symbols.warning),
18 error: colors.red(colors.symbols.cross)
19};
20
21const defaults = {
22 name: '<unknown>',
23 level: 'info',
24 unique: true
25};
26
27const prefix = {
28 level (options) {
29 return symbols[options.level];
30 },
31 template: `{{level}} ${colors.gray('「{{name}}」')}: `
32};
33
34function log (options) {
35 const opts = Object.assign({}, defaults, options);
36 const { id } = options;
37
38 opts.prefix = Object.assign({}, prefix, options.prefix);
39 delete opts.id;
40
41 Object.defineProperty(opts, 'id', {
42 get() {
43 if (!id) {
44 return this.name + (opts.unique ? `-${uuid()}` : '');
45 }
46
47 return id;
48 }
49 });
50
51 if (opts.timestamp) {
52 opts.prefix.template = `[{{time}}] ${opts.prefix.template}`;
53 }
54
55 const log = loglevel.getLogger(opts);
56
57 if (!Object.prototype.hasOwnProperty.call(log, 'id')) {
58 Object.defineProperty(log, 'id', {
59 get() {
60 return opts.id;
61 }
62 });
63 }
64
65 return log;
66}
67
68module.exports = log;
69// NOTE: this is exported so that consumers of webpack-log can use the same
70// version of ansi-colors to decorate log messages without incurring additional
71// dependency overhead
72module.exports.colors = colors;
73// NOTE: This is an undocumented function solely for the purpose of tests.
74// Do not use this method in production code. Using in production code
75// may result in strange behavior.
76module.exports.delLogger = function delLogger(name) {
77 delete loglevel.loggers[name];
78};
79
80module.exports.factories = loglevel.factories;
Note: See TracBrowser for help on using the repository browser.