-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
72 lines (63 loc) · 1.25 KB
/
logger.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
"use strict";
/**
It usage process.env.NODE_ENV to show vesbose log.
*/
var winston = require('winston'),
util = require('util'),
fs = require("fs");
var customLevels = {
levels: {
debug: 0,
info: 1,
warn: 2,
error: 3
},
colors: {
debug: 'blue',
info: 'green',
warn: 'yellow',
error: 'red'
}
};
var logger = new(winston.Logger)({
transports: [
new(winston.transports.Console)({
level: 'debug',
levels: customLevels.levels,
colorize: true
})
]
});
function line(args) {
var parts = [
(new Error()).stack.
replace(/.*(Error|node_modules|logger|native).*\n/g, ''). // remove lines with these words
replace(/\n[\s\S]*$/, ''). // take the first line
replace(/^[\s\S]*?\/home\/ubuntu\/autostage\//, ''). // relative path
replace(/^.*\s+at\s*/, '').
replace(/[\)\(]/g, '')
],
logLine;
logLine = util.format.apply(util, args).replace(/\s+/g, ' ');
parts.push(logLine);
return parts.join(' ');
}
var log = function() {
logger.info(line(arguments));
};
log.i = function() {
logger.info(line(arguments));
};
log.e = function() {
var l = line(arguments);
logger.error(l);
};
log.w = function() {
logger.warn(line(arguments));
};
log.d = function() {
// if(process.env.TRAVIS){
// return;
// }
};
module.exports = log;