0.0.2 • Published 6 years ago

winston-restify v0.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

winston-restify

Another transport to sending logs with winston. Inspired by winston-endpoint

standard travis Code Coverage npm

Installation:

npm install winston-restify --save

Note:

Requires Node >8.0.0.

API Options:

KeyDescription
levellogging-levels
silentsetting to true will turn the console transport off (default: false)
dispatchsetting to false will disable log shipping (default: true)
clientapi-options
basicAuthdescription
debugprint responses status
prependsends the level and message to request (default: { level: true, message: true })

Meta Options:

KeyDescription
methodHTTP method (default: post)
optionsdescription
pathendpoint api (default: '/')
dataobject for sending, supported in POST methods, PUT (default: {})

Example:

This example is available here as well.

'use strict'

const restify = require('restify')
const winston = require('winston')
const winstonRestify = require('winston-restify')

winston
  // HTTP transport included to winston
  .add(
    winstonRestify, {
      silent: true,
      dispatch: true,
      debug: true,
      client: {
        url: 'http://localhost:8080/logger'
      }
    }
  )
  // remove transport from the logger to terminal
  .remove(winston.transports.Console)

const server = restify.createServer()

server.get('/', function (req, res, next) {
  winston.info('sending_logger', {
    method: 'get',
    path: '/logger'
  })
  res.send(200, { info: 'see your terminal!!' })
  next()
})

server.get('/logger', function (req, res, next) {
  console.log('hello logger!!!!')
  next()
})

server.listen(8080, function () {
  console.log('listening on http://localhost:8080/')
})

Tests

npm test

License

MIT

Copyright (c) 2018-present