Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 44 lines (38 sloc) 1.341 kb
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
winston = require 'winston'

exports.Gelfling = winston.transports.Gelfling = class Gelfling extends winston.Transport
  constructor: (options) ->
    @name = 'gelfling'
    @level = options.level || 'info'
    @silent = options.silent || false
    @handleExceptions = options.handleExceptions || false

    @graylogHost = options.graylogHost || 'localhost'
    @graylogPort = options.graylogPort || 12201
    @graylogHostname = options.graylogHostname || require('os').hostname()
    @graylogFacility = options.graylogFacility || 'nodejs'
    @graylogSequence = 0

    @gelfling = require('gelfling')(@graylogHost, @graylogPort, defaults: {facility: @graylogFacility})

  getMessageLevel: (winstonLevel) ->
    mappings =
      verbose: 7
      silly: 7
      debug: 7
      info: 6
      notice: 5
      warn: 4
      error: 3

    if (typeof winstonLevel is "number")
      return winstonLevel
    mappings[winstonLevel] || 6

  log: (level, msg, meta, callback) ->
    if (@silent)
      return callback null, true
    message =
      version: "1.0"
      timestamp: +new Date()/1000 >> 0
      host: @graylogHostname
      facility: @graylogFacility
      short_message: msg
      full_message: meta || {}
      level: @getMessageLevel(level)
    @gelfling.send message
    callback null, true
Something went wrong with that request. Please try again.