monolog
Version:
Log with Monolog
95 lines (84 loc) • 2.57 kB
text/coffeescript
"use strict"
util = require 'util'
events = require 'events'
###
Monolog log channel
It contains a stack of Handlers and a stack of Processors.
and uses them to kstore records that are added to it.
###
class Logger
util.inherits(Logger,events.EventEmitter)
="log"
=100
=200
=250
=300
=400
=500
=550
=600
=1
=
100:'DEBUG'
200:'INFO'
250:'NOTICE'
300:'WARNING'
400:'ERROR'
500:'CRITICAL'
550:'ALERT'
600:'EMERGENCY'
constructor:(="",=[],=[])->
getName:->
pushHandler:(handler)->.unshift(handler);this
popHandler:->.pop()
pushProcessor:(processor)->.unshift(processor);this
popProcessor:->.pop()
#add a log record
addRecord:(level,message,context)->
record=
message:message
context:context
level:level
level_name:Logger.levels[level] or 100
channel:
datetime: new Date
extra:{toString:->'[object Extra]'}
handlerKey = null
for handler,i in
if(handler.isHandling(record)) then handlerKey = i ; break
if handlerKey is null then return false
record = processor(record) for processor in
while [handlerKey] and false == [handlerKey].handle(record,(err,res,record,handler)=>)
handlerKey++
true
debug:(message,context)->
info:(message,context)->
notice:(message,context)->
warning:(message,context)->
error:(message,context)->
critical:(message,context)->
alert:(message,context)->
emergency:(message,context)->
# Checks whether the Logger has a handler that listens on the given level
isHandling:(level)->
record={level}
.some (handler)->handler.isHandling(record)
# Adds a log record at an arbitrary level. ###
log:(level,message,context)->
if typeof(level) is "string" then level = Logger[level]
crit:@::critical
err:@::error
emer:@::emergency
warn:@::warning
addProcessor:@::pushProcessor
addHandler:@::pushHandler
module.exports = Logger