Browse Source

apply pino only when production

Yuki Takei 8 years ago
parent
commit
315878f892
4 changed files with 28 additions and 22 deletions
  1. 6 5
      config/env.dev.js
  2. 8 14
      lib/crowi/index.js
  3. 3 2
      package.json
  4. 11 1
      yarn.lock

+ 6 - 5
config/env.dev.js

@@ -1,10 +1,11 @@
 module.exports = {
+  // DEBUG: '*',
   NODE_ENV: 'development',
-  // MATHJAX: 1,
-  // REDIS_URL: 'redis://localhost:6379/crowi',
-  // ELASTICSEARCH_URI: 'http://localhost:9200/crowi',
+  MATHJAX: 1,
+  REDIS_URL: 'redis://localhost:6379/crowi',
+  ELASTICSEARCH_URI: 'http://localhost:9200/crowi',
   PLUGIN_NAMES_TOBE_LOADED: [
-    // 'crowi-plugin-lsx',
-    // 'crowi-plugin-pukiwiki-like-linker',
+    'crowi-plugin-lsx',
+    'crowi-plugin-pukiwiki-like-linker',
   ]
 }

+ 8 - 14
lib/crowi/index.js

@@ -357,10 +357,6 @@ Crowi.prototype.start = function() {
 
 Crowi.prototype.buildServer = function() {
   var express  = require('express')
-    // , errorHandler   = require('errorhandler')
-    // , morgan         = require('morgan')
-    , pino           = require('pino')
-    , expressPino    = require('express-pino-logger')
     , app = express()
     , env = this.node_env
     ;
@@ -381,29 +377,27 @@ Crowi.prototype.buildServer = function() {
     }
   }
 
-/*
- * commented out morgan because of using pino  -- 2017.06.27 Yuki Takei
- *
   if (env == 'development') {
     //swig.setDefaults({ cache: false });
-    app.use(errorHandler({ dumpExceptions: true, showStack: true }));
+    const morgan = require('morgan');
     app.use(morgan('dev'));
   }
 
   if (env == 'production') {
+    /*
+     * commented out morgan because of using pino  -- 2017.06.27 Yuki Takei
+     *
     var oneYear = 31557600000;
     app.use(morgan('combined'));
     app.use(function (err, req, res, next) {
       res.status(500);
       res.render('500', { error: err });
     });
+     */
+    const pino = require('pino')({extreme: true}, process.stdout);
+    const expressPino = require('express-pino-logger')({pino});
+    app.use(expressPino);
   }
-*/
-
-  // init pino
-  const isExtreme = (env == 'production');
-  const logger = pino({extreme: isExtreme}, process.stdout);
-  app.use(expressPino({logger}));
 
   return Promise.resolve(app);
 };

+ 3 - 2
package.json

@@ -32,8 +32,8 @@
     "prebuild:dev": "env-cmd config/env.dev.js npm run plugin:def",
     "prebuild:prod": "npm run plugin:def",
     "prestart": "npm run build:prod",
-    "server:dev:watch": "env-cmd config/env.dev.js node-dev app.js --watch | pino-clf common",
-    "server:dev": "env-cmd config/env.dev.js node app.js | pino-clf common",
+    "server:dev:watch": "env-cmd config/env.dev.js node-dev app.js --watch",
+    "server:dev": "env-cmd config/env.dev.js node app.js",
     "server:prod": "node app.js --production | pino-clf common",
     "server": "npm run server:dev:watch",
     "start": "npm run server:prod",
@@ -126,6 +126,7 @@
     "concurrently": "^3.4.0",
     "easy-livereload": "^1.2.0",
     "mocha": "^3.2.0",
+    "morgan": "^1.8.2",
     "node-dev": "^3.1.3",
     "proxyquire": "^1.7.11",
     "sinon": "^2.1.0",

+ 11 - 1
yarn.lock

@@ -878,7 +878,7 @@ basic-auth-connect@~1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/basic-auth-connect/-/basic-auth-connect-1.0.0.tgz#fdb0b43962ca7b40456a7c2bb48fe173da2d2122"
 
-basic-auth@^1.1.0:
+basic-auth@^1.1.0, basic-auth@~1.1.0:
   version "1.1.0"
   resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-1.1.0.tgz#45221ee429f7ee1e5035be3f51533f1cdfd29884"
 
@@ -3742,6 +3742,16 @@ mongoose@^4.9.4:
     regexp-clone "0.0.1"
     sliced "1.0.1"
 
+morgan@^1.8.2:
+  version "1.8.2"
+  resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.8.2.tgz#784ac7734e4a453a9c6e6e8680a9329275c8b687"
+  dependencies:
+    basic-auth "~1.1.0"
+    debug "2.6.8"
+    depd "~1.1.0"
+    on-finished "~2.3.0"
+    on-headers "~1.0.1"
+
 mpath@0.3.0:
   version "0.3.0"
   resolved "https://registry.yarnpkg.com/mpath/-/mpath-0.3.0.tgz#7a58f789e9b5fd3c94520634157960f26bd5ef44"