12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- {
- "name": "morgan",
- "description": "http request logger middleware for node.js",
- "version": "1.3.2",
- "author": {
- "name": "Jonathan Ong",
- "email": "me@jongleberry.com",
- "url": "http://jongleberry.com"
- },
- "contributors": [
- {
- "name": "Douglas Christopher Wilson",
- "email": "doug@somethingdoug.com"
- }
- ],
- "license": "MIT",
- "repository": {
- "type": "git",
- "url": "git://github.com/expressjs/morgan"
- },
- "dependencies": {
- "basic-auth": "1.0.0",
- "depd": "0.4.5",
- "on-finished": "2.1.0"
- },
- "devDependencies": {
- "istanbul": "0.3.2",
- "mocha": "~1.21.0",
- "should": "~4.0.4",
- "supertest": "~0.13.0"
- },
- "files": [
- "LICENSE",
- "HISTORY.md",
- "index.js"
- ],
- "engines": {
- "node": ">= 0.8.0"
- },
- "scripts": {
- "test": "mocha --check-leaks --reporter spec --bail",
- "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot",
- "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --check-leaks --reporter spec"
- },
- "readme": "# morgan\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n[![Gratipay][gratipay-image]][gratipay-url]\n\nHTTP request logger middleware for node.js\n\n> Named after [Dexter](http://en.wikipedia.org/wiki/Dexter_Morgan), a show you should not watch until completion.\n\n## API\n\n```js\nvar morgan = require('morgan')\n```\n\n### morgan(format, options)\n\nCreate a new morgan logger middleware function using the given `format` and `options`.\nThe `format` argument may be a string of a predefined name (see below for the names),\na string of a format string, or a function that will produce a log entry.\n\n#### Options\n\nMorgan accepts these properties in the options object.\n\n#### buffer\n\nBuffer duration before writing logs to the `stream`, defaults to `false`. When\nset to `true`, defaults to `1000 ms`.\n\n#### immediate\n\nWrite log line on request instead of response. This means that a requests will\nbe logged even if the server crashes, _but data from the response (like the\nresponse code, content length, etc.) cannot be logged_.\n\n##### skip\n\nFunction to determine if logging is skipped, defaults to `false`. This function\nwill be called as `skip(req, res)`.\n\n```js\n// EXAMPLE: only log error responses\nmorgan('combined', {\n skip: function (req, res) { return res.statusCode < 400 }\n})\n```\n\n##### stream\n\nOutput stream for writing log lines, defaults to `process.stdout`.\n\n#### Predefined Formats\n\nThere are various pre-defined formats provided:\n\n##### combined\n\nStandard Apache combined log output.\n\n```\n:remote-addr - :remote-user [:date] \":method :url HTTP/:http-version\" :status :res[content-length] \":referrer\" \":user-agent\"\n```\n\n##### common\n\nStandard Apache common log output.\n\n```\n:remote-addr - :remote-user [:date] \":method :url HTTP/:http-version\" :status :res[content-length]\n```\n\n##### dev\n\nConcise output colored by response status for development use. The `:status`\ntoken will be colored red for server error codes, yellow for client error\ncodes, cyan for redirection codes, and uncolored for all other codes.\n\n```\n:method :url :status :response-time ms - :res[content-length]\n```\n\n##### short\n\nShorter than default, also including response time.\n\n```\n:remote-addr :remote-user :method :url HTTP/:http-version :status :res[content-length] - :response-time ms\n```\n\n##### tiny\n\nThe minimal output.\n\n```\n:method :url :status :res[content-length] - :response-time ms\n```\n\n#### Tokens\n\n- `:req[header]` ex: `:req[Accept]`\n- `:res[header]` ex: `:res[Content-Length]`\n- `:http-version`\n- `:response-time`\n- `:remote-addr`\n- `:remote-user`\n- `:date`\n- `:method`\n- `:url`\n- `:referrer`\n- `:user-agent`\n- `:status`\n\nTo define a token, simply invoke `morgan.token()` with the name and a callback function. The value returned is then available as \":type\" in this case:\n```js\nmorgan.token('type', function(req, res){ return req.headers['content-type']; })\n```\n\n## Examples\n\n### express/connect\n\nSimple app that will log all request in the Apache combined format to STDOUT\n\n```js\nvar express = require('express')\nvar morgan = require('morgan')\n\nvar app = express()\n\napp.use(morgan('combined'))\n\napp.get('/', function (req, res) {\n res.send('hello, world!')\n})\n```\n\n### vanilla http server\n\nSimple app that will log all request in the Apache combined format to STDOUT\n\n```js\nvar finalhandler = require('finalhandler')\nvar http = require('http')\nvar morgan = require('morgan')\n\n// create \"middleware\"\nvar logger = morgan('combined')\n\nhttp.createServer(function (req, res) {\n var done = finalhandler(req, res)\n logger(req, res, function (err) {\n if (err) return done(err)\n\n // respond to request\n res.setHeader('content-type', 'text/plain')\n res.end('hello, world!')\n })\n})\n```\n\n### write logs to a file\n\nSimple app that will log all request in the Apache combined format to the file \"access.log\"\n\n```js\nvar express = require('express')\nvar fs = require('fs')\nvar morgan = require('morgan')\n\nvar app = express()\n\n// create a write stream (in append mode)\nvar accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'})\n\n// setup the logger\napp.use(morgan('combined', {stream: accessLogStream}))\n\napp.get('/', function (req, res) {\n res.send('hello, world!')\n})\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/morgan.svg?style=flat\n[npm-url]: https://npmjs.org/package/morgan\n[travis-image]: https://img.shields.io/travis/expressjs/morgan.svg?style=flat\n[travis-url]: https://travis-ci.org/expressjs/morgan\n[coveralls-image]: https://img.shields.io/coveralls/expressjs/morgan.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/expressjs/morgan?branch=master\n[downloads-image]: http://img.shields.io/npm/dm/morgan.svg?style=flat\n[downloads-url]: https://npmjs.org/package/morgan\n[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat\n[gratipay-url]: https://www.gratipay.com/dougwilson/\n",
- "readmeFilename": "README.md",
- "bugs": {
- "url": "https://github.com/expressjs/morgan/issues"
- },
- "_id": "morgan@1.3.2",
- "_from": "morgan@~1.3.0"
- }
|