Permalink
Browse files

[logger] refactored into pluggable thing

  • Loading branch information...
1 parent e0db616 commit bb94a54e3b909a95e0cbec6733e852f7092474d6 @dscape committed May 13, 2012
Showing with 28 additions and 3 deletions.
  1. +24 −0 logger/index.js
  2. +3 −3 nano.js
  3. +1 −0 package.json
View
@@ -0,0 +1,24 @@
+var verbose = (process.env.NANO_ENV==='testing')
+ , logger = exports
+ ;
+
+module.exports = function logging(cfg) {
+ var logStrategy = cfg ? cfg.log : undefined;
+ this.cfg = cfg;
+ if (typeof logStrategy !== 'function') {
+ if(verbose) {
+ logStrategy = function consoleLog(eventId, args) {
+ console.log(eventId, args);
+ };
+ }
+ else logStrategy = function noop(){};
+ }
+
+ return function logEvent(prefix) {
+ var eventId =
+ (prefix ? prefix + '-' : '') + (~~(Math.random() * 1e9)).toString(36);
+ return function log() {
+ logStrategy.call(this, eventId, [].slice.call(arguments,0));
+ };
+ };
+};
View
@@ -635,10 +635,10 @@ module.exports = exports = nano = function database_module(cfg) {
request_opts.jar = !!cfg.jar;
request = require('request').defaults(request_opts);
}
-
+
// assuming a cfg.log inside cfg
- logging = require('./logging')(cfg);
-
+ logging = require('./logger')(cfg);
+
try {
path = u.parse(cfg.url);
path_array = path.pathname.split('/').filter(function(e) { return e; });
View
@@ -26,6 +26,7 @@
{ "async" : "0.1.x"
, "specify" : "0.4.x"
, "nock" : "0.13.x"
+ , "errs" : "0.2.x"
}
, "scripts" :
{ "test" : "ls -tr tests/*/*.js | NOCK=on xargs -I{} node {}" }

0 comments on commit bb94a54

Please sign in to comment.