[Pkg-javascript-commits] [node-coveralls] 122/332: Added ability to turn on debug logging via environment variable

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 9 13:53:49 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-coveralls.

commit 8bf0bf952cba404d3c0b49f22783cf49ba1dbb8f
Author: mattjmorrison <mattjmorrison at mattjmorrison.com>
Date:   Thu Dec 5 22:44:10 2013 -0600

    Added ability to turn on debug logging via environment variable
    
    For the grunt-karma-coveralls project, I need to be able to turn on
    debug level logging but without using `process.argv`. This will allow me
    to do so.
    
    This addresses this issue:
    https://github.com/mattjmorrison/grunt-karma-coveralls/issues/2
    
    and can be fixed with this commit:
    https://github.com/mattjmorrison/grunt-karma-coveralls/commit/4bd6e2b58647dda4a6335fa6077334d8021e23c0
---
 lib/logger.js  | 22 ++++++++++++++++------
 test/logger.js | 21 +++++++++++++++++++++
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/lib/logger.js b/lib/logger.js
index 985b67b..30a6c60 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -1,8 +1,18 @@
 module.exports = function(){
-  if (process.argv[2]) {
-    if (~['-v', '--verbose'].indexOf(process.argv[2])) {
-      return require('log-driver')({level : 'debug'});
-    }
-  }
-  return require('log-driver')({level : 'warn'});
+  return require('log-driver')({level : getLogLevel()});
 };
+
+function getLogLevel(){
+  if (hasVerboseCommandLineOption() || hasDebugEnvVariable()) {
+    return 'debug';
+  }
+  return 'warn';
+}
+
+function hasVerboseCommandLineOption(){
+    return process.argv[2] && ~['-v', '--verbose'].indexOf(process.argv[2]);
+}
+
+function hasDebugEnvVariable(){
+    return process.env.NODE_COVERALLS_DEBUG == 1;
+}
diff --git a/test/logger.js b/test/logger.js
index c6899db..61d20bc 100644
--- a/test/logger.js
+++ b/test/logger.js
@@ -8,4 +8,25 @@ describe("logger", function(){
     var logger = require('../index').logger();
     logger.level.should.equal('debug');
   });
+
+  it ("should log at debug level when NODE_COVERALLS_DEBUG is set in env", function(){
+    process.argv = [];
+    process.env.NODE_COVERALLS_DEBUG = 1;
+    var logger = require('../index').logger();
+    logger.level.should.equal('debug');
+  });
+
+  it ("should log at debug level when NODE_COVERALLS_DEBUG is set in env as a string", function(){
+    process.argv = [];
+    process.env.NODE_COVERALLS_DEBUG = '1';
+    var logger = require('../index').logger();
+    logger.level.should.equal('debug');
+  });
+
+  it ("should log at warn level when NODE_COVERALLS_DEBUG not set and no --verbose", function(){
+    process.argv = [];
+    process.env.NODE_COVERALLS_DEBUG = 0;
+    var logger = require('../index').logger();
+    logger.level.should.equal('warn');
+  });
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-coveralls.git



More information about the Pkg-javascript-commits mailing list