1 |
|
2 |
|
3 | "use strict";
|
4 |
|
5 | const colors = require("ansi-colors");
|
6 |
|
7 | const noColor = process.argv.indexOf('--no-color') > 0;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function getTime(level) {
|
18 | const time = new Date().toLocaleTimeString('en-US', { hour12: false });
|
19 | if (noColor) {
|
20 | return '[' + time + ']';
|
21 | } else {
|
22 | switch (level) {
|
23 | case 1:
|
24 | return colors.yellowBright('[') + colors.gray(time) + colors.yellowBright(']');
|
25 | case 2:
|
26 | return colors.red('[') + colors.gray(time) + colors.red(']');
|
27 | case -1:
|
28 | return colors.gray('[') + colors.gray(time) + colors.gray(']');
|
29 | default:
|
30 | return '[' + colors.gray(time) + ']';
|
31 | }
|
32 |
|
33 | }
|
34 | }
|
35 |
|
36 |
|
37 | function log() {
|
38 | console.log.apply(console, Array.prototype.concat.apply([getTime()], arguments));
|
39 | return this;
|
40 | }
|
41 |
|
42 | function info() {
|
43 | console.info.apply(console, Array.prototype.concat.apply([getTime(-1)], arguments));
|
44 | return this;
|
45 | }
|
46 |
|
47 | function warn() {
|
48 | console.warn.apply(console, Array.prototype.concat.apply([getTime(1)], arguments));
|
49 | return this;
|
50 | }
|
51 |
|
52 | function error() {
|
53 | console.error.apply(console, Array.prototype.concat.apply([getTime(2)], arguments));
|
54 | return this;
|
55 | }
|
56 |
|
57 | module.exports = log;
|
58 | module.exports.info = info;
|
59 | module.exports.warn = warn;
|
60 | module.exports.error = error; |
\ | No newline at end of file |