pages
Version:
AngularJS / Node.js sidekick.
49 lines (28 loc) • 1.03 kB
text/coffeescript
bold = '\x1B[0;1m'
red = '\x1B[0;31m'
green = '\x1B[0;32m'
reset = '\x1B[0m'
yellow = '\x1B[1;33m'
cyan = '\x1B[1;36m'
Create JSON structures based on the log type.
convert = (msg, type) ->
if typeof msg is 'object'
if type
logMsg = { }
logMsg[type] = msg
msg = JSON.stringify logMsg
else
msg = JSON.stringify msg
msg
log = (msg) -> console.log "#{msg}"
## Public API ##
module.exports =
This `stream` comes from Connect middleware, so we can capture HTTP requests if we're not client-only.
stream:
write: (msg) -> log convert msg
info: (msg) -> log convert msg, 'info'
warn: (msg) -> log "#{yellow}#{convert(msg, 'warn')}#{reset}"
err: (msg) -> log "#{red}#{convert(msg, 'error')}#{reset}"
ok: (msg) -> log "#{green}#{convert(msg, 'ok')}#{reset}"
cyan: (msg) -> log "#{cyan}#{convert(msg)}#{reset}"
bold: (msg) -> log "#{bold}#{convert(msg)}#{reset}"