mvc-log.js
2.26 KB
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
var styles = {
'bold' : '\x1B[1m%s\x1B[0m',
'italic' : '\x1B[3m%s\x1B[0m',
'underline' : '\x1B[4m%s\x1B[0m',
'inverse' : '\x1B[7m%s\x1B[0m',
'strikethrough' : '\x1B[9m%s\x1B[0m',
'white' : '\x1B[37m%s\x1B[0m',
'grey' : '\x1B[90m%s\x1B[0m',
'black' : '\x1B[30m%s\x1B[0m',
'blue' : '\x1B[34m%s\x1B[0m',
'cyan' : '\x1B[36m%s\x1B[0m',
'green' : '\x1B[32m%s\x1B[0m',
'magenta' : '\x1B[35m%s\x1B[0m',
'red' : '\x1B[31m%s\x1B[0m',
'yellow' : '\x1B[33m%s\x1B[0m',
'whiteBG' : '\x1B[47m%s\x1B[0m',
'greyBG' : '\x1B[49m%s\x1B[0m',
'blackBG' : '\x1B[40m%s\x1B[0m',
'blueBG' : '\x1B[31%s\x1B[0m',
'cyanBG' : '\x1B[46m%s\x1B[0m',
'greenBG' : '\x1B[42m%s\x1B[0m',
'magentaBG' : '\x1B[45m%s\x1B[0m',
'redBG' : '\x1B[41m%s\x1B[0m',
'yellowBG' : '\x1B[43m%s\x1B[0m'
};
module.exports = {
log : function(text, type) {
var logType, //日志的类型,page,ajax,pjax,success
logrank;
//日志级别,默认debug
if ( typeof (type) === 'undefined') {
logType = 'success';
logrank = '-debug';
} else if ( typeof (type) === 'string') {
logType = type;
logrank = '-debug';
} else if ( typeof (type) === "object") {
logType = type.type || "success";
logrank = type.rank || "-debug";
}
global.logRank=global.logRank||'-dev';
if (logrank !== global.logRank)
{
return;
}
var colors = {
ajax : styles.magenta,
page : styles.cyan,
pjax : styles.blue,
success : styles.green
};
console.log(colors[logType], text);
},
error : function(text, opts) {
var logRank = typeof (opts) === 'undefined' ? '-debug' : (opts.rank || '-debug');
global.logRank=global.logRank||'-dev';
if (logRank !== global.logRank)
return;
console.log(styles.red, text);
},
warn : function(text, opts) {
var logRank = typeof (opts) === 'undefined' ? '-debug' : (opts.rank || '-debug');
global.logRank=global.logRank||'-dev';
if (logRank !== global.logRank)
return;
console.log(styles.yellow, text);
}
};