Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

morgan

Package Overview
Dependencies
Maintainers
6
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

morgan - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

HISTORY.md

26

index.js

@@ -6,2 +6,3 @@ /*!

* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed

@@ -55,8 +56,5 @@ */

// format name
var fmt = exports[format] || format || exports.default;
// format function
var fmt = compile(exports[format] || format || exports.default)
// compile format
if ('function' != typeof fmt) fmt = compile(fmt);
// options

@@ -121,5 +119,5 @@ var stream = options.stream || process.stdout

/**
* Compile `fmt` into a function.
* Compile `format` into a function.
*
* @param {String} fmt
* @param {Function|String} format
* @return {Function}

@@ -129,7 +127,17 @@ * @api private

function compile(fmt) {
fmt = fmt.replace(/"/g, '\\"');
function compile(format) {
if (typeof format === 'function') {
// already compiled
return format
}
if (typeof format !== 'string') {
throw new TypeError('argument format must be a function or string')
}
var fmt = format.replace(/"/g, '\\"')
var js = ' return "' + fmt.replace(/:([-\w]{2,})(?:\[([^\]]+)\])?/g, function(_, name, arg){
return '"\n + (tokens["' + name + '"](req, res, "' + arg + '") || "-") + "';
}) + '";'
return new Function('tokens, req, res', js);

@@ -136,0 +144,0 @@ };

{
"name": "morgan",
"description": "http request logger middleware for node.js",
"version": "1.2.3",
"version": "1.3.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",

@@ -23,2 +23,7 @@ "contributors": [

},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {

@@ -25,0 +30,0 @@ "node": ">= 0.8.0"

# morgan
[![NPM version](https://badge.fury.io/js/morgan.svg)](http://badge.fury.io/js/morgan)
[![Build Status](https://travis-ci.org/expressjs/morgan.svg?branch=master)](https://travis-ci.org/expressjs/morgan)
[![Coverage Status](https://img.shields.io/coveralls/expressjs/morgan.svg?branch=master)](https://coveralls.io/r/expressjs/morgan)
[![Gittip](http://img.shields.io/gittip/dougwilson.svg)](https://www.gittip.com/dougwilson/)
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Gratipay][gratipay-image]][gratipay-url]

@@ -15,7 +16,3 @@ HTTP request logger middleware for node.js

```js
var express = require('express')
var morgan = require('morgan')
var app = express()
app.use(morgan('combined'))
var morgan = require('morgan')
```

@@ -29,15 +26,2 @@

```js
// a pre-defined name
morgan('combined')
// a format string
morgan(':remote-addr :method :url')
// a custom function
morgan(function (req, res) {
return req.method + ' ' + req.url
})
```
#### Options

@@ -64,3 +48,3 @@

```js
// only log error responses
// EXAMPLE: only log error responses
morgan('combined', {

@@ -141,13 +125,80 @@ skip: function (req, res) { return res.statusCode < 400 }

## Examples
## License
### express/connect
The MIT License (MIT)
Simple app that will log all request in the Apache combined format to STDOUT
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
```js
var express = require('express')
var morgan = require('morgan')
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
var app = express()
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
app.use(morgan('combined'))
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
app.get('/', function (req, res) {
res.send('hello, world!')
})
```
### vanilla http server
Simple app that will log all request in the Apache combined format to STDOUT
```js
var finalhandler = require('finalhandler')
var http = require('http')
var morgan = require('morgan')
// create "middleware"
var logger = morgan('combined')
http.createServer(function (req, res) {
var done = finalhandler(req, res)
logger(req, res, function (err) {
if (err) return done(err)
// respond to request
res.setHeader('content-type', 'text/plain')
res.end('hello, world!')
})
})
```
### write logs to a file
Simple app that will log all request in the Apache combined format to the file "access.log"
```js
var express = require('express')
var fs = require('fs')
var morgan = require('morgan')
var app = express()
// create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'})
// setup the logger
app.use(morgan('combined', {stream: accessLogStream}))
app.get('/', function (req, res) {
res.send('hello, world!')
})
```
## License
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/morgan.svg?style=flat
[npm-url]: https://npmjs.org/package/morgan
[travis-image]: https://img.shields.io/travis/expressjs/morgan.svg?style=flat
[travis-url]: https://travis-ci.org/expressjs/morgan
[coveralls-image]: https://img.shields.io/coveralls/expressjs/morgan.svg?style=flat
[coveralls-url]: https://coveralls.io/r/expressjs/morgan?branch=master
[downloads-image]: http://img.shields.io/npm/dm/morgan.svg?style=flat
[downloads-url]: https://npmjs.org/package/morgan
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
[gratipay-url]: https://www.gratipay.com/dougwilson/
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc