Koa.js Tutorial
Koa.js Useful Resources
Selected Reading
- Koa.js - Resources
- Koa.js - Scaffolding
- Koa.js - Logging
- Koa.js - RESTful APIs
- Koa.js - Database
- Koa.js - Caching
- Koa.js - Compression
- Koa.js - Authentication
- Koa.js - Sessions
- Koa.js - Cookies
- Koa.js - Static Files
- Koa.js - File Uploading
- Koa.js - Form Data
- Koa.js - Templating
- Koa.js - Cascading
- Koa.js - Error Handling
- Koa.js - Redirects
- Koa.js - Response Object
- Koa.js - Request Object
- Koa.js - HTTP Methods
- Koa.js - URL Building
- Koa.js - Routing
- Koa.js - Generators
- Koa.js - Hello World
- Koa.js - Environment
- Koa.js - Overview
- Koa.js - Home
Koa.js Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Koa.js - Logging
Koa.js - Logging
Logging is quite useful when creating web apppcations as they tell us where exactly things went wrong. We also get the context for the things that went wrong and can come up with possible solutions for the same.
To enable logging in Koa, we need the middleware, koa-logger. Install it using the following command.
$ npm install --save-dev koa-logger
Now in your apppcation, 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.psten(3000)
Run this server and visit any route on the server. You should see the logs pke −
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.
Advertisements