Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koa-modules/morgan
morgan for koa
https://github.com/koa-modules/morgan
Last synced: 24 days ago
JSON representation
morgan for koa
- Host: GitHub
- URL: https://github.com/koa-modules/morgan
- Owner: koa-modules
- License: mit
- Created: 2015-03-02T20:33:30.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-25T08:39:35.000Z (almost 9 years ago)
- Last Synced: 2024-11-11T06:03:44.738Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 63
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
- awesome-koa - koa-morgan - 基于Morgan的中间件。 ![](https://img.shields.io/github/stars/koa-modules/morgan.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-morgan.svg?style=flat-square) (仓库 / 中间件)
README
# koa-morgan
> HTTP request logger middleware for koa.
> [morgan] wrapper for koa's middleware.[![NPM version][npm-img]][npm-url]
[![NPM Downloads][downloads-image]][npm-url]
[![Build status][travis-img]][travis-url]
[![Test coverage][coveralls-img]][coveralls-url]
[![Dependency status][david-img]][david-url]
[![License][license-img]][license-url]## Install
```sh
$ npm install --save koa-morgan
```## Usage
### **=1.x**, 100%, working with **morgan** and **koa-v2**
```js
const fs = require('fs')
const Koa = require('koa')
const morgan = require('koa-morgan')// create a write stream (in append mode)
const accessLogStream = fs.createWriteStream(__dirname + '/access.log',
{ flags: 'a' })
const app = new Koa()// setup the logger
app.use(morgan('combined', { stream: accessLogStream }))app.use((ctx) => {
ctx.body = 'hello, world!'
})app.listen(2333)
```### **=0.x**, working with **koa-v1**
```js
var koa = require('koa');
var morgan = require('koa-morgan');
var app = koa();app.use(morgan.middleware(format, options));
```
[npm-img]: https://img.shields.io/npm/v/koa-morgan.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-morgan
[travis-img]: https://img.shields.io/travis/koa-modules/morgan.svg?style=flat-square
[travis-url]: https://travis-ci.org/koa-modules/morgan
[coveralls-img]: https://img.shields.io/coveralls/koa-modules/morgan.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/koa-modules/morgan?branch=master
[license-img]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square
[license-url]: LICENSE
[david-img]: https://img.shields.io/david/koa-modules/morgan.svg?style=flat-square
[david-url]: https://david-dm.org/koa-modules/morgan
[downloads-image]: https://img.shields.io/npm/dm/koa-morgan.svg?style=flat-square
[morgan]: https://github.com/expressjs/morgan