-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogging.coffee
44 lines (34 loc) · 864 Bytes
/
logging.coffee
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
# (C) 2012 Avi Romanoff <aviromanoff at gmail.com>
# Based on socket.io-node's MIT licensed logger.
_ = require 'underscore'
colors = require "colors"
class Logger
constructor: (@prefix='') ->
_.each @_levels, (name) =>
@[name] = =>
@_log.apply(@, [name].concat(_.toArray(arguments)))
_levels: [
'error'
'warn'
'info'
'debug'
]
_colors: [
'red'
'yellow'
'cyan'
'grey'
]
_pad: (str) ->
max = 0
for level in @_levels
max = Math.max(max, level.length)
if str.length < max
return str + new Array(max - str.length + 1).join(' ')
return str
_log: (type) ->
index = @_levels.indexOf(type)
console.log.apply(
console,
[" " + @._pad(type)[@_colors[index]] + " - " + @prefix.bold].concat(_.toArray(arguments)[1..]))
module.exports = {Logger: Logger}