How to use the bunyan function from restify
Find comprehensive JavaScript restify.bunyan code examples handpicked from public code repositorys.
restify.bunyan provides an interface for using the Bunyan logger with Restify framework.
29 30 31 32 33 34 35 36 37 38
if (!opts.logger) { opts.logger = {}; } opts.logger.name = 'workflow-api'; opts.logger.serializers = restify.bunyan.serializers; opts.logger.streams = opts.logger.streams || [ { level: 'info', stream: process.stdout
GitHub: ProboCI/probo
108 109 110 111 112 113 114 115 116 117
// Add probo's request logger server.use(requestLogger({logger: this.log})); // Extend logger using the plugin. server.use(restify.plugins.requestLogger({ serializers: restify.bunyan.serializers, })); server.use(function(req, res, next) { req.log.info({req: req}, 'REQUEST');
+ 3 other calls in file
How does restify.bunyan work?
restify.bunyan is a middleware for the Restify framework that sets up a Bunyan logger instance with a unique req_id for each incoming request, and logs various events related to the request and response lifecycle, such as request start, response sent, and errors encountered.
114 115 116 117 118 119 120 121 122 123
if (options.log === undefined) { this.log = bunyan.createLogger({ name: 'vmapi', level: 'debug', serializers: restify.bunyan.serializers }); } else { this.log = options.log; }
148 149 150 151 152 153 154 155 156
*/ this.mdr_server = mod_restify.createServer({ name: MDR_SERVER_NAME, log: this.mdr_log.child({ component: 'HttpServer', serializers: mod_restify.bunyan.serializers }), handleUpgrades: true });
+ 3 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
const restify = require("restify"); const bunyan = require("bunyan"); const restifyBunyanLogger = require("restify-bunyan-logger"); const log = bunyan.createLogger({ name: "myapp" }); const server = restify.createServer({ name: "myapp", log: log, }); server.use(restifyBunyanLogger()); server.get("/hello/:name", (req, res, next) => { req.log.info({ name: req.params.name }, "hello"); res.send("hello " + req.params.name); return next(); }); server.listen(8080, () => { log.info("server listening on port 8080"); });
In this example, we create a new bunyan logger and pass it to the restify server as its logging provider. We then add the restify-bunyan-logger plugin to the server, which automatically logs all incoming requests and responses using the logger we provided. Finally, we define a simple GET endpoint that logs a message with the logger and returns a greeting.
21 22 23 24 25 26 27 28 29 30 31
name: 'boilerplateapi', level: 'debug', serializers: { err: Logger.stdSerializers.err, req: Logger.stdSerializers.req, res: restify.bunyan.serializers.response } });
restify.createServer is the most popular function in restify (1059 examples)