whistlepunk
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "whistlepunk", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/LeanKit-Labs/whistlepunk", | ||
@@ -21,2 +21,6 @@ "description": "Logging abstraction that signals any enabled adapters of a new log message.", | ||
"url": "http://nerdventure.io/" | ||
}, | ||
{ | ||
"name": "Brian Edgerton", | ||
"url": "https://github.com/brianedgerton" | ||
} | ||
@@ -31,3 +35,3 @@ ], | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha -r spec/helpers/node-setup.js spec", | ||
"test": "mocha ./spec/**/*.spec.js -R spec", | ||
"coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -x 'spec/**/*' -- -r spec/helpers/node-setup.js spec spec/*.spec.js", | ||
@@ -40,2 +44,3 @@ "show-coverage": "open ./coverage/lcov-report/index.html" | ||
"lodash": "2.4.1", | ||
"machina": "1.0.0-1", | ||
"moment": "2.9.0", | ||
@@ -45,6 +50,13 @@ "when": "3.6.4" | ||
"devDependencies": { | ||
"gulp": "^3.8.11", | ||
"gulp-istanbul": "^0.6.0", | ||
"gulp-jshint": "^1.9.2", | ||
"gulp-mocha": "^2.0.0", | ||
"istanbul": "~0.3.2", | ||
"jshint-stylish": "^1.0.0", | ||
"mocha": "~2.1.0", | ||
"open": "0.0.5", | ||
"postal": "~0.12.3", | ||
"should": "~4.6.1" | ||
"should": "~4.6.1", | ||
"sinon": "^1.12.2" | ||
}, | ||
@@ -51,0 +63,0 @@ "engines": { |
@@ -71,7 +71,7 @@ #Whistlepunk | ||
* return a promise | ||
* provide an init method that returns a promise for asynchronous setup | ||
* provide a `constraint` predicate that filters log entries (one is provided by default that filters by level) | ||
* accept a fount instance as a second argument to the factory method | ||
Debug adapter | ||
#### Debug adapter - synchronous example | ||
```js | ||
@@ -97,1 +97,36 @@ var debug = require( "debug" ); | ||
``` | ||
#### Autohost Socket adapter - asynchronous example | ||
```js | ||
var noOpAdapter = { onLog: function() {} }; | ||
var adapter; | ||
function createAhAdapter( fount ) { | ||
var host; | ||
return { | ||
// whistlepunk will call this when present | ||
// and cache log messages for this adapter | ||
// until the promise resolves | ||
init: function() { | ||
return fount.resolve( "ah" ) | ||
.then( function( _host ) { | ||
host = _host; | ||
} ); | ||
}, | ||
onLog: function( data ) { | ||
if ( host && host.notifyClients ) { | ||
host.notifyClients( data.type, data ); | ||
} | ||
} | ||
}; | ||
} | ||
// because need fount to get a handle to the | ||
// autohost instance, return a no-op adapter | ||
// if it's missing | ||
module.exports = function( config, fount ) { | ||
adapter = adapter || ( fount ? createAhAdapter( fount ) : noOpAdapter ); | ||
return adapter; | ||
}; | ||
``` |
@@ -5,13 +5,17 @@ var noOpAdapter = { onLog: function() {} }; | ||
function createAhAdapter( fount ) { | ||
return fount | ||
.resolve( "ah" ) | ||
.then( function( host ) { | ||
return { | ||
onLog: function( data ) { | ||
if ( host && host.notifyClients ) { | ||
host.notifyClients( data.type, data ); | ||
} | ||
} | ||
}; | ||
} ); | ||
var host; | ||
return { | ||
init: function() { | ||
return fount.resolve( "ah" ) | ||
.then( function( _host ) { | ||
host = _host; | ||
} ); | ||
}, | ||
onLog: function( data ) { | ||
if ( host && host.notifyClients ) { | ||
host.notifyClients( data.type, data ); | ||
} | ||
} | ||
}; | ||
} | ||
@@ -22,2 +26,2 @@ | ||
return adapter; | ||
}; | ||
}; |
@@ -15,2 +15,2 @@ var debug = require( "debug" ); | ||
return debugAdapter; | ||
}; | ||
}; |
@@ -37,2 +37,2 @@ var colors = require( "colors" ); | ||
return adapter; | ||
}; | ||
}; |
@@ -5,2 +5,3 @@ var _ = require( "lodash" ); | ||
var when = require( "when" ); | ||
var builtIn = getAdapters(); | ||
@@ -23,21 +24,43 @@ | ||
function wireUp( config, channel ) { | ||
return function onAdapter( adapter ) { | ||
var newSub = channel | ||
.subscribe( adapter.topic || "#", adapter.onLog ) | ||
.constraint( adapter.constraint || defaultConstraint( config ) ); | ||
if ( adapter.subscription ) { | ||
adapter.subscription.unsubscribe(); | ||
function wireUp( adapterFsm, config, channel, adapter ) { | ||
var fsm; | ||
var init; | ||
var handler = adapter.onLog; | ||
if ( _.isFunction( adapter.init ) ) { | ||
init = adapter.init(); | ||
if ( init && init.then ) { | ||
adapterFsm.register( adapter, init ); | ||
handler = adapterFsm.onLog.bind( adapterFsm, adapter ); | ||
} | ||
adapter.subscription = newSub; | ||
}; | ||
} | ||
var newSub = channel | ||
.subscribe( adapter.topic || "#", handler ) | ||
.constraint( adapter.constraint || defaultConstraint( config ) ); | ||
if ( adapter.subscription ) { | ||
adapter.subscription.unsubscribe(); | ||
} | ||
adapter.subscription = newSub; | ||
} | ||
module.exports = function( channel, config, fount ) { | ||
_.each( config.adapters, function( adapterCfg, name ) { | ||
var adapterFsm = require( "./adapter.fsm" ); | ||
return _.map( config.adapters, function( adapterCfg, name ) { | ||
var adapterPath = builtIn[ name ] || require.resolve( name ); | ||
var adapter = require( adapterPath )( adapterCfg, fount ); | ||
when( adapter ) | ||
.then( wireUp( adapterCfg, channel ) ); | ||
wireUp( adapterFsm, adapterCfg, channel, adapter ); | ||
return adapter; | ||
} ); | ||
}; | ||
}; |
@@ -6,9 +6,9 @@ var _ = require( "lodash" ); | ||
var Logger = require( "./Logger.js" )( log ); | ||
require( "./configParser" )( log, config, fount ); | ||
var adapters = require( "./configParser" )( log, config, fount ); | ||
function loggerFactory( namespace ) { | ||
return new Logger( namespace ); | ||
return new Logger( namespace, adapters ); | ||
} | ||
return loggerFactory; | ||
}; | ||
}; |
var util = require( "util" ); | ||
var _ = require( "lodash" ); | ||
module.exports = function( channel ) { | ||
var logLevels = [ "off", "error", "warn", "info", "debug" ]; | ||
function Logger( ns ) { | ||
function Logger( ns, adapters ) { | ||
this.namespace = ns || "whistlepunk"; | ||
this.adapters = adapters; | ||
} | ||
@@ -21,2 +23,10 @@ | ||
Logger.prototype.reset = function reset() { | ||
_.each( this.adapters, function( adapter ) { | ||
adapter.subscription.unsubscribe(); | ||
} ); | ||
}; | ||
logLevels.slice( 1 ).forEach( function( level ) { | ||
@@ -29,2 +39,2 @@ Logger.prototype[ level ] = function() { | ||
return Logger; | ||
}; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12559
11
174
131
6
11
1
+ Addedmachina@1.0.0-1
+ Addedmachina@1.0.0-1(transitive)