Skip to content

Another transport to sending logs with winston.

License

Notifications You must be signed in to change notification settings

carvalhoviniciusluiz/winston-restify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

Key Description
level logging-levels
silent setting to true will turn the console transport off (default: false)
dispatch setting to false will disable log shipping (default: true)
client api-options
basicAuth description
debug print responses status
prepend sends the level and message to request (default: { level: true, message: true })

Meta Options:

Key Description
method HTTP method (default: post)
options description
path endpoint api (default: '/')
data object 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

About

Another transport to sending logs with winston.

Resources

License

Stars

Watchers

Forks

Packages

No packages published