[Pkg-javascript-commits] [node-log-driver] 03/49: initial commit. prototype probably maybe almost works.

Bastien Roucariès rouca at moszumanska.debian.org
Thu Feb 22 12:56:58 UTC 2018


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

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

commit d6632e3bbecf00da6740b0a99f5436c676695fc6
Author: cainus <gregg at caines.ca>
Date:   Sun Mar 17 19:51:29 2013 -0700

    initial commit. prototype probably maybe almost works.
---
 .gitignore   |  1 +
 index.js     | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json | 29 +++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)

diff --git a/.gitignore b/.gitignore
index f356293..a57a19f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@ logs
 results
 
 npm-debug.log
+node_modules/
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..8838581
--- /dev/null
+++ b/index.js
@@ -0,0 +1,51 @@
+var util = require('util');
+
+LogDriver = function(options){
+  options = options || {};
+  var logger = this;
+  if (options.format){
+    this.format = options.format;
+  }
+  this.levels = options.levels || ['error', 'warn', 'info', 'debug', 'trace'];
+  this.level = options.level || this.levels[this.levels.length - 1];
+  if (this.levels.indexOf(this.level) === -1){
+    throw new Error("Log level '" +
+                    this.level +
+                    "' does not exist in level list '" + JSON.stringify() + "'");
+  }
+  this.levels.forEach(function(level){
+    if (logger.levels.indexOf(level) <= logger.levels.indexOf(logger.level)){
+      logger[level] = function(){
+        var args = Array.prototype.slice.call(arguments);
+        args.unshift(level);  // log level is added as the first parameter
+        console.log(logger.format.apply(logger, args));
+      };
+    } else {
+      logger[level] = function(){/* no-op, because this log level is ignored */};
+    }
+  });
+};
+
+LogDriver.prototype.format = function(){
+  var args = Array.prototype.slice.call(arguments, [1]); // change arguments to an array, but
+                                                         // drop the first item (log level)
+  var out = "[" + arguments[0] + "] " + JSON.stringify(new Date()) + " ";
+  args.forEach(function(arg){
+    out += " " + util.inspect(arg);
+  });
+  return out;
+};
+
+logger = function(options){
+  logger.logger = new LogDriver(options);
+  return logger.logger;
+};
+
+module.exports = logger();
+
+/*
+var l = logger({"level" : "info"}); //, format : function(){return JSON.stringify(arguments);}});
+l.error("something went horribly wrong");
+l.info("FYI", {asdf:true});
+l.debug("debug", {show:false});
+*/
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..829c308
--- /dev/null
+++ b/package.json
@@ -0,0 +1,29 @@
+{
+      "name": "log-driver",
+      "description" : "log-driver is a simple logging framework for logging to stdout",
+      "keywords" : ["logging", "logger", "log"],
+      "version": "1.0.0",
+      "bugs": {
+       "url": "https://github.com/cainus/logdriver/issues"
+      },
+      "scripts" : {
+        "test" : "make test"
+      },
+      "maintainers": [
+        {
+          "name": "Gregg Caines",
+          "email": "gregg at caines.ca",
+          "web": "http://caines.ca"
+        } 
+      ],
+      "dependencies": {
+      },
+      "devDependencies" : {
+          "mocha" : "1.8.1",
+          "should" : "1.1.0"
+      },
+      "engines" : {
+                   "node" : ">=0.8.6",
+                   "npm" : "1.1.65"
+                  }
+}

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



More information about the Pkg-javascript-commits mailing list