Skip to content

Commit

Permalink
Add common log format
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jul 19, 2014
1 parent 1e6f0c6 commit d67c5fe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unreleased

* Add `:remote-user` token
* Add `combined` log format
* Add `common` log format
* Remove non-standard grey color from `dev` format

1.1.1 / 2014-05-20
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ morgan({ format: 'dev', skip: function(req, res){ return res.statusCode === 304;
#### Predefined Formats

- `combined` - Standard Apache combined log output.
- `common` - Standard Apache common log output.
- `short` - Shorter than default, also including response time.
- `tiny` - The minimal.
- `dev` - Concise output colored by response status for development use.
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ exports.format = function(name, fmt){

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.
*/
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,22 @@ describe('logger()', function () {
})
})

describe('common', function () {
it('should match expectations', function (done) {
var server = createServer({format: 'common'})

request(server)
.get('/')
.set('Authorization', 'Basic dGo6')
.end(function (err, res) {
if (err) return done(err)
var line = lastLogLine.replace(/\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+/, '_timestamp_')
line.should.equal(res.text + ' - tj [_timestamp_] "GET / HTTP/1.1" 200 -\n')
done()
})
})
})

describe('default', function () {
it('should match expectations', function (done) {
var server = createServer({format: 'default'})
Expand Down

0 comments on commit d67c5fe

Please sign in to comment.