Skip to content
Myr

Removed CommonLogger, use Logger

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parents 6469046, 5e74723 · Browse files · 7 files+108 added−77 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+108 added−77 removed

  • tests:+0 added−24 removed
  • other:+108 added−53 removed

7 files+108 added−77 removed

modified:examples/chat/app.js+1 added-1 removed
modified:examples/upload/app.js+1 added-1 removed
deleted:lib/express/plugins/common-logger.js-50 removed
added:lib/express/plugins/logger.js+105 added
12// Express - Logger - Copyright Aaron Heckmann <aaronheckmann+express@gmail.com> (MIT Licensed)34/**5 * Log formats6 */7 8var formats = {9 common: function (event) {10 return [event.request.connection.remoteAddress, 11 '-', 12 '-',13 '[' + formatDate(new Date) + ']', 14 '"' + event.request.method.toUpperCase() + ' ' + (event.request.url.pathname || '/') + 15 ' HTTP/' + event.request.httpVersion + '"',16 event.request.response.status,17 event.request.response.headers['content-length'] || 018 ].join(' ')19 },20 combined: function (event) {21 return [formats.common(event),22 '"' + (event.request.headers['referrer'] || event.request.headers['referer'] || '-') + '"',23 '"' + (event.request.headers['user-agent'] || '') + '"'24 ].join(' ')25 },26 sinatra: function (event, start) {27 return formats.common(event) + " " + ((Number(new Date) - start)/1000).toFixed(3)28 },29 plot: function (event, start) {30 return Number(new Date) - start31 }32}333435/**36 * Months.37 */3839var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']4041/**42 * Format _date_.43 *44 * @param {Date} date45 * @return {string}46 * @api private47 */48 49function formatDate(date) {50 var d = date.getDate(),51 m = months[date.getMonth()],52 y = date.getFullYear(),53 h = date.getHours(),54 mi = date.getMinutes(),55 s = date.getSeconds()56 return (d < 10 ? '0' : '') + d + '/' + m + '/' + y + ' ' +57 (h < 10 ? '0' : '') + h + ':' + (mi < 10 ? '0' : '') + 58 mi + ':' + (s < 10 ? '0' : '') + s59}606162// --- Logger6364exports.Logger = Plugin.extend({ 65 extend: {66 67 /**68 * Initialize logger options.69 *70 * Options:71 *72 * - format73 * 'common' outputs log in CommonLog format (DEFAULT)74 * 'combined' outputs log in Apache Combined format75 * 'sinatra' outputs log in Sinatra format76 * 'plot' outputs request duration in milliseconds only77 *78 * @param {hash} options79 * @api private80 */8182 init: function(options) {83 this.merge(options || {})84 }85 },86 87 on: {88 89 /**90 * Start timer.91 */92 93 request: function(event) {94 this.start = Number(new Date)95 },96 97 /**98 * Output log data.99 */100 101 response: function(event) {102 puts((formats[exports.Logger.format] || formats["common"])(event, this.start))103 }104 }105})
modified:lib/express/plugins.js+1 added-1 removed
modified:spec/node.js-1 removed
23 unmodified lines
24 'static',25 'plugins',26 'plugins.cache',27 'plugins.view',28 'plugins.common-logger',28 'plugins.content-length',29 'plugins.method-override',30 'plugins.body-decoder',31 'plugins.redirect',
17 unmodified lines
deleted:spec/spec.plugins.common-logger.js-23 removed