1 | term = require('./colors').colors
|
2 | nullColors = {}
|
3 |
|
4 | for curColor in ['cyan', 'green', 'yellow', 'red']
|
5 | nullColors[curColor] = (msg)-> msg
|
6 |
|
7 |
|
8 | clean = false
|
9 | colors = term
|
10 | level = 2
|
11 |
|
12 | levels =
|
13 | debug: 1
|
14 | info: 2
|
15 | warn: 3
|
16 | critical: 4
|
17 |
|
18 | debug = (msg)->
|
19 | log colors.cyan("debug ", true), msg, 1
|
20 |
|
21 | info = (msg)->
|
22 | log colors.green("info ", true), msg, 2
|
23 |
|
24 | warn = (msg)->
|
25 | log colors.yellow("WARN ", true), msg, 3
|
26 |
|
27 | critical = (msg)->
|
28 | log colors.red("ERROR!!", true), msg, 4
|
29 |
|
30 | log = (desc, msg, logLevel)->
|
31 | return if logLevel < level
|
32 | lines = msg.toString().split "\n"
|
33 | for line in lines
|
34 | if clean
|
35 | console.log line
|
36 | else
|
37 | console.log " % #{desc} | #{line}"
|
38 |
|
39 | module.exports =
|
40 | debug: debug
|
41 | info: info
|
42 | warn: warn
|
43 | critical: critical
|
44 |
|
45 | setClean: (toggle)->
|
46 | clean = toggle
|
47 |
|
48 | setColor: (toggle)->
|
49 | if toggle
|
50 | colors = term
|
51 | else
|
52 | colors = nullColors
|
53 | debug "Color output disabled"
|
54 |
|
55 | setLevel: (lvl)->
|
56 | level = levels[lvl]
|