carvalhoviniciusluiz /
winston-restify
| 1 | 'use strict' |
||
| 2 | |||
| 3 | const restify = require('restify') |
||
| 4 | const winston = require('winston') |
||
| 5 | const winstonRestify = require('..') |
||
| 6 | |||
| 7 | winston |
||
| 8 | // HTTP transport included to winston |
||
| 9 | .add( |
||
| 10 | winstonRestify, { |
||
| 11 | dispatch: true, |
||
| 12 | client: { |
||
| 13 | url: 'http://localhost:8080' |
||
| 14 | } |
||
| 15 | } |
||
| 16 | ) |
||
| 17 | // remove transport from the logger to terminal |
||
| 18 | .remove(winston.transports.Console) |
||
| 19 | |||
| 20 | const server = restify.createServer() |
||
| 21 | |||
| 22 | server.get('/', function (req, res, next) { |
||
| 23 | winston.info('sending_logger', { |
||
| 24 | method: 'get', |
||
| 25 | path: '/logger' |
||
| 26 | }) |
||
| 27 | res.send(200, { info: 'see your terminal!!' }) |
||
| 28 | next() |
||
| 29 | }) |
||
| 30 | |||
| 31 | server.get('/logger', function (req, res, next) { |
||
| 32 | console.log('hello logger!!!!') |
||
|
0 ignored issues
–
show
Debugging Code
introduced
by
Loading history...
|
|||
| 33 | next() |
||
| 34 | }) |
||
| 35 | |||
| 36 | server.listen(8080, function () { |
||
| 37 | console.log('listening on http://localhost:8080/') |
||
|
0 ignored issues
–
show
|
|||
| 38 | }) |
||
| 39 |