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.1.1 to 1.2.0

11

History.md

@@ -0,1 +1,12 @@

1.2.0 / 2014-07-19
==================
* Add `:remote-user` token
* Add `combined` log format
* Add `common` log format
* Add `morgan(format, options)` function signature
* Deprecate `default` format -- use `combined` format instead
* Deprecate not providing a format
* Remove non-standard grey color from `dev` format
1.1.1 / 2014-05-20

@@ -2,0 +13,0 @@ ==================

71

index.js
/*!
* Morgan | Connect - logger
* morgan
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* Copyright(c) 2014 Jonathan Ong
* MIT Licensed

@@ -12,5 +13,8 @@ */

var auth = require('basic-auth')
var bytes = require('bytes');
var deprecate = require('depd')('morgan')
var onFinished = require('finished')
/*!
/**
* Default log buffer duration.

@@ -22,7 +26,6 @@ */

/**
* Log requests with the given `options` or a `format` string.
* Create a logger middleware.
*
* See README.md for documentation of options and formatting.
*
* @param {String|Function|Object} format or options
* @param {String|Function} format
* @param {Object} [options]
* @return {Function} middleware

@@ -32,9 +35,17 @@ * @api public

exports = module.exports = function logger(options) {
if (options && typeof options !== 'object') {
options = { format: options };
} else {
options = options || {};
exports = module.exports = function morgan(format, options) {
if (typeof format === 'object') {
options = format
format = options.format || 'default'
// smart deprecation message
deprecate('morgan(options): use morgan(' + (typeof format === 'string' ? JSON.stringify(format) : 'format') + ', options) instead')
}
if (format === undefined) {
deprecate('undefined format: specify a format')
}
options = options || {}
// output on request instead of response

@@ -47,3 +58,3 @@ var immediate = options.immediate;

// format name
var fmt = exports[options.format] || options.format || exports.default;
var fmt = exports[format] || format || exports.default;

@@ -94,4 +105,2 @@ // compile format

function logRequest(){
res.removeListener('finish', logRequest);
res.removeListener('close', logRequest);
if (skip(req, res)) return;

@@ -106,9 +115,6 @@ var line = fmt(exports, req, res);

logRequest();
// proxy end to output logging
} else {
res.on('finish', logRequest);
res.on('close', logRequest);
onFinished(res, logRequest)
}
next();

@@ -164,6 +170,19 @@ };

/**
* Apache combined log format.
*/
exports.format('combined', ':remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"')
/**
* Apache common log format.
*/
exports.format('common', ':remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length]')
/**
* Default format.
*/
exports.format('default', ':remote-addr - - [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"');
exports.format('default', ':remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"');
deprecate.property(exports, 'default', 'default format: use combined format')

@@ -174,3 +193,3 @@ /**

exports.format('short', ':remote-addr - :method :url HTTP/:http-version :status :res[content-length] - :response-time ms');
exports.format('short', ':remote-addr :remote-user :method :url HTTP/:http-version :status :res[content-length] - :response-time ms');

@@ -195,3 +214,3 @@ /**

var fn = compile('\x1b[90m:method :url \x1b[' + color + 'm:status \x1b[90m:response-time ms - :res[content-length]\x1b[0m');
var fn = compile('\x1b[0m:method :url \x1b[' + color + 'm:status \x1b[0m:response-time ms - :res[content-length]\x1b[0m');

@@ -264,2 +283,12 @@ return fn(tokens, req, res);

/**
* remote user
*/
exports.token('remote-user', function (req) {
var creds = auth(req)
var user = (creds && creds.name) || '-'
return user;
})
/**
* HTTP version

@@ -266,0 +295,0 @@ */

{
"name": "morgan",
"description": "http request logger middleware for node.js",
"version": "1.1.1",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com",
"twitter": "https://twitter.com/jongleberry"
},
"version": "1.2.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
"Douglas Christopher Wilson <doug@somethingdoug.com>"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/expressjs/morgan.git"
},
"bugs": {
"mail": "me@jongleberry.com",
"url": "https://github.com/expressjs/morgan/issues"
},
"repository": "expressjs/morgan",
"dependencies": {
"bytes": "1.0.0"
"basic-auth": "1.0.0",
"bytes": "1.0.0",
"depd": "0.4.2",
"finished": "~1.2.2"
},
"devDependencies": {
"istanbul": "0.2.10",
"mocha": "~1.19.0",
"should": "~3.3.1",
"supertest": "~0.12.0"
"istanbul": "0.3.0",
"mocha": "~1.20.1",
"should": "~4.0.4",
"supertest": "~0.13.0"
},

@@ -39,6 +27,6 @@ "engines": {

"scripts": {
"test": "mocha --require should --reporter dot",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require should --reporter dot",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require should --reporter spec"
"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"
}
}

@@ -1,5 +0,9 @@

# 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)](https://travis-ci.org/expressjs/morgan) [![Coverage Status](https://img.shields.io/coveralls/expressjs/morgan.svg)](https://coveralls.io/r/expressjs/morgan)
# morgan
Logging middleware for node.js http apps.
[![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)
HTTP request logger middleware for node.js
> Named after [Dexter](http://en.wikipedia.org/wiki/Dexter_Morgan), a show you should not watch until completion.

@@ -14,26 +18,23 @@

var app = express()
app.use(morgan())
app.use(morgan('combined'))
```
### morgan(options)
### morgan(format, options)
Morgan may be passed options to configure the logging output. The options may be passed as a predefined format, formatting string, function, or object.
Create a new morgan logger middleware function using the given `format` and `options`.
The `format` argument may be a string of a predefined name (see below for the names),
a string of a format string, or a function that will produce a log entry.
```js
morgan() // default
morgan('short')
morgan('tiny')
morgan({ format: 'dev', immediate: true })
morgan(':method :url - :referrer')
morgan(':req[content-type] -> :res[content-type]')
morgan(function(tokens, req, res){ return 'some format string' })
morgan({ format: 'dev', skip: function(req, res){ return res.statusCode === 304; }})
```
// a pre-defined name
morgan('combined')
#### Predefined Formats
// a format string
morgan(':remote-addr :method :url')
- `default` - Standard output.
- `short` - Shorter than default, also including response time.
- `tiny` - The minimal.
- `dev` - Concise output colored by response status for development use.
// a custom function
morgan(function (req, res) {
return req.method + ' ' + req.url
})
```

@@ -44,13 +45,75 @@ #### Options

- `format` - Format string or Setting, see below for format tokens.
- `stream` - Output stream, defaults to `stdout`.
- `buffer` - Buffer duration, defaults to `1000 ms` when `true`.
- `immediate` - Write log line on request instead of response (for response times).
- `skip` - Function to determine if logging is skipped, called as `skip(req, res)`, defaults to `false`.
#### buffer
All default formats are defined this way, however the api is also public:
Buffer duration before writing logs to the `stream`, defaults to `false`. When
set to `true`, defaults to `1000 ms`.
#### immediate
Write log line on request instead of response. This means that a requests will
be logged even if the server crashes, but data from the response cannot be logged
(like the response code).
##### skip
Function to determine if logging is skipped, defaults to `false`. This function
will be called as `skip(req, res)`.
```js
morgan.format('name', 'string or function')
// only log error responses
morgan('combined', {
skip: function (req, res) { return res.statusCode < 400 }
})
```
##### stream
Output stream for writing log lines, defaults to `process.stdout`.
#### Predefined Formats
There are various pre-defined formats provided:
##### combined
Standard Apache combined log output.
```
:remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"
```
##### common
Standard Apache common log output.
```
:remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length]
```
##### dev
Concise output colored by response status for development use. The `:status`
token will be colored red for server error codes, yellow for client error
codes, cyan for redirection codes, and uncolored for all other codes.
```
:method :url :status :response-time ms - :res[content-length]
```
##### short
Shorter than default, also including response time.
```
:remote-addr :remote-user :method :url HTTP/:http-version :status :res[content-length] - :response-time ms
```
##### tiny
The minimal output.
```
:method :url :status :res[content-length] - :response-time ms
```
#### Tokens

@@ -63,2 +126,3 @@

- `:remote-addr`
- `:remote-user`
- `:date`

@@ -65,0 +129,0 @@ - `:method`

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