From 8cfc24b95f8c2d947b2d342e1c6e3a59aa7e82ee Mon Sep 17 00:00:00 2001
From: Austin King <shout@ozten.com>
Date: Fri, 9 Mar 2012 16:18:29 -0800
Subject: [PATCH] Adding dev_bid and default_bid which have millisecond
 resolution. Fixes Issue#1254 and Issue#1255

---
 bin/browserid          |  2 +-
 config/local.json      |  2 +-
 config/production.json |  2 +-
 lib/configuration.js   |  5 ++++-
 lib/custom_logger.js   | 21 +++++++++++++++++++++
 5 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 lib/custom_logger.js

diff --git a/bin/browserid b/bin/browserid
index 5802ba36d..718dc44ba 100755
--- a/bin/browserid
+++ b/bin/browserid
@@ -135,7 +135,7 @@ app.use(function(req, resp, next) {
 
 var static_root = path.join(__dirname, "..", "resources", "static");
 
-app.use(cachify.setup(assets(config.get('supported_languages')), 
+app.use(cachify.setup(assets(config.get('supported_languages')),
         {
           prefix: 'v',
           production: config.get('use_minified_resources'),
diff --git a/config/local.json b/config/local.json
index d8726dfff..960bdf2e9 100644
--- a/config/local.json
+++ b/config/local.json
@@ -8,7 +8,7 @@
   "database": {
     "driver": "json"
   },
-  "express_log_format": "dev",
+  "express_log_format": "dev_bid",
   "email_to_console": true
 }
 
diff --git a/config/production.json b/config/production.json
index 966f30951..972c2899f 100644
--- a/config/production.json
+++ b/config/production.json
@@ -33,7 +33,7 @@
   "debug_lang": "it-CH",
   // locale directory should be overridden
   "locale_directory": "/home/app/code/locale",
-  "express_log_format": "default",
+  "express_log_format": "default_bid",
   "email_to_console": false,
   // var path should be overridded
   // "var_path": "xxx",
diff --git a/lib/configuration.js b/lib/configuration.js
index 1b443b575..0676211e8 100644
--- a/lib/configuration.js
+++ b/lib/configuration.js
@@ -22,6 +22,9 @@ fs = require('fs'),
 convict = require('convict'),
 cjson = require('cjson');
 
+// Side effect - Adds default_bid and dev_bid to express.logger formats
+require('./custom_logger');
+
 // verify the proper version of node.js is in use
 try {
   var required = 'unknown';
@@ -154,7 +157,7 @@ var conf = module.exports = convict({
   debug_lang: 'string = "it-CH"',
   supported_languages: 'array { string }* = [ "en-US" ]',
   locale_directory: 'string = "locale"',
-  express_log_format: 'string [ "default", "dev" ] = "default"',
+  express_log_format: 'string [ "default_bid", "dev_bid", "default", "dev", "short", "tiny" ] = "default"',
   keysigner_url: {
     format: 'string?',
     env: 'KEYSIGNER_URL'
diff --git a/lib/custom_logger.js b/lib/custom_logger.js
new file mode 100644
index 000000000..6ba0514bf
--- /dev/null
+++ b/lib/custom_logger.js
@@ -0,0 +1,21 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Enhances connect logger middleware - custom formats. See lib/configuration for usage.
+ *
+ * Note: No exports, ya I feel dirty too.
+ */
+var logger = require('express').logger;
+
+logger.format('default_bid',
+    ':remote-addr - - :date-millis ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"');
+
+logger.format('dev_bid', ':date-millis :method :url :status :response-time ms');
+
+logger.token('date-millis', function (req) {
+  var d = req._startTime,
+      t = '' + d.getTime();
+  return '[' + d.toUTCString() + ']@' + t.slice(-4);
+});
\ No newline at end of file
-- 
GitLab