做用:用來輸出用戶請求日誌app
參數:options或者format字符串ui
tokens: format格式url
Formats:縮寫日誌
default ‘:remote-addr – – [:date] 「:method :url HTTP/:http-version」 :status :res[content-length] 「:referrer」 「:user-agent」‘ short ‘:remote-addr – :method :url HTTP/:http-version :status :res[content-length] – :response-time ms’ tiny ‘:method :url :status :res[content-length] – :response-time ms’ dev concise output colored by response status for development use
例子:新建logger.jscode
var connect = require('connect'); var app = connect() .use(connect.logger()) .use(function (req, res) { res.end('hello world\n'); }) .listen(3000);
connect.logger()orm
127.0.0.1 - - [Mon, 23 Sep 2013 05:14:18 GMT] "GET / HTTP/1.1" 200 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi t/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36" 127.0.0.1 - - [Mon, 23 Sep 2013 05:14:18 GMT] "GET /favicon.ico HTTP/1.1" 200 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"
connect.logger(‘short’)token
127.0.0.1 - GET / HTTP/1.1 200 - - 9 ms 127.0.0.1 - GET /favicon.ico HTTP/1.1 200 - - 1 ms
connect.logger(‘dev’)ci
GET / 200 5ms GET /favicon.ico 200 1ms
connect.logger(function(tokens, req, res){ return ‘some format string’ })開發
some format string some format string
因此在開發環境,咱們日誌設置成dev就行了。rem