UNPKG

997 Btext/coffeescriptView Raw
1term = require('./colors').colors
2nullColors = {}
3
4for curColor in ['cyan', 'green', 'yellow', 'red']
5 nullColors[curColor] = (msg)-> msg
6
7# Toggle-able options
8clean = false
9colors = term
10level = 2
11
12levels =
13 debug: 1
14 info: 2
15 warn: 3
16 critical: 4
17
18debug = (msg)->
19 log colors.cyan("debug ", true), msg, 1
20
21info = (msg)->
22 log colors.green("info ", true), msg, 2
23
24warn = (msg)->
25 log colors.yellow("WARN ", true), msg, 3
26
27critical = (msg)->
28 log colors.red("ERROR!!", true), msg, 4
29
30log = (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
39module.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]