Skip to content

Commit

Permalink
v2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhhai committed Apr 20, 2016
1 parent 440799d commit 766ec07
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ A wrapper for [log4js-node](https://github.com/nomiddlename/log4js-node) which s
Log message is forked from Express (Connect) logger [file](https://github.com/nomiddlename/log4js-node/blob/master/lib/connect-logger.js).

## Note
This branch is use to Koa v0.x & v1.x.
To use [Koa v2.x](https://github.com/koajs/koa/tree/v2.x), please check the [v2.x](https://github.com/dominhhai/koa-log4js/tree/v2.x) branch.
This branch is use to [Koa v2.x](https://github.com/koajs/koa/tree/v2.x).
To use Koa v0.x & v1.x, please check the [master](https://github.com/dominhhai/koa-log4js/tree/master) branch.

## Installation

Expand All @@ -18,7 +18,7 @@ $ npm i --save koa-log4@1
$ npm i --save koa-log4@2
```

___The default logger is for [koa v2.x](https://github.com/koajs/koa/tree/v2.x)
___The default logger is for [koa v2.x](https://github.com/koajs/koa/tree/v2.x)___
```
$ npm i --save koa-log4
```
Expand Down
16 changes: 8 additions & 8 deletions koa-logger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'

const co = require('co')
const levels = require('log4js').levels
var DEFAULT_FORMAT = ':remote-addr - -' +
const DEFAULT_FORMAT = ':remote-addr - -' +
' ":method :url HTTP/:http-version"' +
' :status :content-length ":referrer"' +
' ":user-agent"'
Expand Down Expand Up @@ -47,13 +48,12 @@ function getKoaLogger (logger4js, options) {
var fmt = options.format || DEFAULT_FORMAT
var nolog = options.nolog ? createNoLogCondition(options.nolog) : null

return function *(next) {
var ctx = this
return co.wrap(function *(ctx, next) {
// mount safety
if (ctx.request._logging) return yield next
if (ctx.request._logging) return yield next()

// nologs
if (nolog && nolog.test(ctx.originalUrl)) return yield next
if (nolog && nolog.test(ctx.originalUrl)) return yield next()
if (thislogger.isLevelEnabled(level) || options.level === 'auto') {
var start = new Date()
var writeHead = ctx.response.writeHead
Expand All @@ -78,7 +78,7 @@ function getKoaLogger (logger4js, options) {
}
}

yield next
yield next()
// hook on end request to emit the log entry of the HTTP request.
ctx.response.responseTime = new Date() - start
// status code response level handling
Expand All @@ -101,8 +101,8 @@ function getKoaLogger (logger4js, options) {
}

// ensure next gets always called
yield next
}
yield next()
})
}

/**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koa-log4",
"version": "1.0.0",
"version": "2.0.0",
"description": "log4js-node support Koa-middleware",
"main": "index.js",
"scripts": {
Expand All @@ -22,6 +22,7 @@
},
"homepage": "https://github.com/dominhhai/koa-log4js#readme",
"dependencies": {
"co": "^4.6.0",
"log4js": "^0.6.35"
},
"devDependencies": {
Expand Down

0 comments on commit 766ec07

Please sign in to comment.