-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
81 lines (58 loc) · 1.89 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* @author Stanislav Kalashnik <[email protected]>
* @license GNU GENERAL PUBLIC LICENSE Version 3
*/
'use strict';
const
util = require('util'),
colors = require('colors/safe'),
dateConfig = {hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit'},
logger = {};
function time () {
const date = new Date();
return date.toLocaleString('en', dateConfig) + '.' + (+date).toString().substr(-3);
}
// export colorization
logger.colors = colors;
logger.info = function () {
console.log(colors.grey(time()), util.format.apply(util, arguments));
};
logger.warn = function () {
console.log(colors.bgYellow.black(time()), util.format.apply(util, arguments));
};
logger.fail = function () {
console.log(colors.bgRed(time()), util.format.apply(util, arguments));
};
logger.inspect = function ( data ) {
util.inspect(data, {colors: true, depth: 5}).split('\n').forEach(function ( line ) {
logger.info(line);
});
};
// add individual report methods for a task
logger.wrap = function ( title ) {
const result = {
// export colorization
colors: colors,
// configurable task message
format: '[%s] %s',
// task name
title: colors.cyan(title),
info: function () {
logger.info(result.format, result.title, util.format.apply(util, arguments));
},
warn: function () {
logger.warn(result.format, result.title, util.format.apply(util, arguments));
},
fail: function () {
logger.fail(result.format, result.title, util.format.apply(util, arguments));
},
inspect: function ( data ) {
util.inspect(data, {colors: true, depth: 5}).split('\n').forEach(function ( line ) {
result.info(line);
});
}
};
return result;
};
// public
module.exports = logger;