add logger
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Aaron Heckmann · committed by Aaron Heckmann · parent ce94168 · Browse files · 3 files·+111 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+111 added−0 removed
- other:+111 added−0 removed
Provenance
- Commit
5e74723- Tree
7d5efe4- Author
Aaron Heckmann <aaron.heckmann@gmail.com>- Committer
Aaron Heckmann <aaron.heckmann@gmail.com>- Parent
ce94168
3 files changed+111 added−0 removed
modified:lib/express/plugins/common-logger.js+5 added
28 unmodified lines2930313233343536373839404114 unmodified lines28 unmodified lines
// --- CommonLogger exports.CommonLogger = Plugin.extend({ extend: { init: function() { puts("CommonLogger is deprecated. Please Use(Logger)") } }, on: { /** * Output log data.14 unmodified linesadded:lib/express/plugins/logger.js+105 added
1+2+// Express - Logger - Copyright Aaron Heckmann <aaronheckmann+express@gmail.com> (MIT Licensed)3+4+/**5+ * Log formats6+ */7+ 8+var 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+}33+34+35+/**36+ * Months.37+ */38+39+var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']40+41+/**42+ * Format _date_.43+ *44+ * @param {Date} date45+ * @return {string}46+ * @api private47+ */48+ 49+function 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+}60+61+62+// --- Logger63+64+exports.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+ */81+82+ 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
7 unmodified lines8910111213147 unmodified linesutils.mixin(require('express/plugins/cookie'))utils.mixin(require('express/plugins/session'))utils.mixin(require('express/plugins/profiler'))utils.mixin(require('express/plugins/common-logger'))utils.mixin(require('express/plugins/logger'))utils.mixin(require('express/plugins/content-length'))utils.mixin(require('express/plugins/method-override'))