For enabling logging in Koa, we need the middleware, koa-logger. Install it using:
$ npm install --save-dev koa-loggerNow in your applicaiton, add the following code to enable logging:
var logger = require('koa-logger') var koa = require('koa') var app = koa() app.use(logger()) app.use(function*(){ this.body = "Hello Logger"; }) app.listen(3000)Run this server and visit any route on the server. You should see the logs like:
Now if you get an error on a specific route or request, these logs should help you figure out what went wrong in each of them.
No comments:
Post a Comment