Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

whistlepunk

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

whistlepunk - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

src/log.js

5

CHANGELOG.md
## 0.3.x
## 0.3.2
* Use "" as default namespace
* Use correct console calls for stdOut adapter
* Add alternate api to whistelpunk
## 0.3.1

@@ -4,0 +9,0 @@ * Fix bug in loading adapters from relative paths

13

package.json
{
"name": "whistlepunk",
"version": "0.3.1",
"version": "0.3.2",
"homepage": "https://github.com/LeanKit-Labs/whistlepunk",

@@ -28,2 +28,11 @@ "description": "Logging abstraction that signals any enabled adapters of a new log message.",

"url": "https://github.com/brianedgerton"
},
{
"name": "Derick Bailey",
"url": "http://derickbailey.com",
"email": "derickbailey@gmail.com"
},
{
"name": "Michael Tuttle",
"url": "https://github.com/openam"
}

@@ -44,3 +53,3 @@ ],

"colors": "1.0.3",
"debug": "2.1.3",
"debug": "2.2.0",
"lodash": "3.x",

@@ -47,0 +56,0 @@ "machina": "1.x",

# Whistlepunk
[![Version npm](https://img.shields.io/npm/v/whistlepunk.svg?style=flat)](https://www.npmjs.com/package/whistlepunk)
[![npm Downloads](https://img.shields.io/npm/dm/whistlepunk.svg?style=flat)](https://www.npmjs.com/package/whistlepunk)
[![Dependencies](https://img.shields.io/david/LeanKit-Labs/whistlepunk.svg?style=flat)](https://david-dm.org/LeanKit-Labs/whistlepunk)
> *noun* - a lumberjack who operates the signal wire running to a donkey engine whistle.

@@ -12,5 +16,41 @@

```javascript
var postal = require("postal");
var whistlepunk = require("whistlepunk");
var config = {
adapters: {
stdOut: {
level: 4,
bailIfDebug: true, // disables stdOut if DEBUG=* is in play
timestamp: {
local: true, // defaults to UTC
format: "MMM-D-YYYY hh:mm:ss A" // ex: Jan 1, 2015 10:15:20 AM
},
topic: "#", // default topic
},
"debug": {
level: 4
}
}
};
var loggerFactory = whistlepunk(postal, config);
var logger = loggerFactory();
logger.warn("Watch it, I'm warning you!");
```
### Alternate API
A common use case we've run into is that multiple modules need logging but a dependency on a shared loggerFactory instance gets cumbersome and introduces limitations in setup due to temporal coupling.
Whistlepunk now provides a singleton log instance that you can provide configuration to even after log instances have been created. Any calls to these uninitialized logs will simply no-op until some configuration has been provided.
This also supports use cases where you may want to change log configuration during the lifetime of the application.
```javascript
var whistlepunk = require("whistlepunk").log;
var config = {
adapters: {
stdOut: {
level: 5,

@@ -29,8 +69,21 @@ bailIfDebug: true, // disables stdOut if DEBUG=* is in play

};
var postal = require("postal");
var logger = require("whistlepunk")(postal, config);
logger.warn("Watch it, I'm warning you!");
var logger = whistlepunk( "my.topic" );
logger.warn( "no configuration was provided, no one will see this" );
whistlepunk( config );
logger.info( "now that an adapter was added, this will show up" );
// creating additional log instances that use different topics
// is simple and doesn't require you to provide the configuration
// nor do you need to carry around the same loggerFactory instance.
var altLogger = whistlepunk( "off.topic" );
altLogger.info( "that reminds me ..." );
```
Any other module can get access to the same log factory by using `require( "whistlepunk" ).log;` and not need to pass around shared references.
The trade-off for these features is that you _can_ create a race condition in your setup where some log entries could no-op. Careful planning in how you initialize will avoid this problem.
## Configuration
### Log Levels

@@ -89,13 +142,16 @@ The log levels available are specified as integers (as in the above `level` value under each adapter's configuration). Specifying a log level includes each level up to the level specified. For example, specifying a log level of "3" (info), will include warn (2) and error (1) log messages as well.

```javascript
var postal = require("postal");
var whistlepunk = require("whistlepunk");
var config = {
adapters: {
stdOut: {
level: 5,
level: 4,
bailIfDebug: true // disables stdOut if DEBUG=* is in play
},
"debug": {
level: 5
level: 4
},
autohost: {
level: 5
level: 4
}

@@ -105,4 +161,5 @@ }

// assuming autohost instance is assigned to a "host" variable
var logger = require("whistlepunk")(postal, config, host.fount);
var loggerFactory = whistlepunk(postal, config, host.fount);
var logger = loggerFactory();
logger.debug("More info than you'd typically want to sift through....");

@@ -109,0 +166,0 @@ ```

var colors = require( "colors" );
var _ = require( "lodash" );
var adapter;
var adapter, lastConfig;
function configure( config, formatter ) {
if( adapter && lastConfig && _.eq( lastConfig, config ) ) {
return;
}
lastConfig = config;
var envDebug = !!process.env.DEBUG;

@@ -15,5 +19,12 @@

var logType = {
info: "info",
warn: "warn",
debug: "log",
error: "error"
};
colors.setTheme( theme );
adapter = adapter || {
adapter = {
onLog: function( data ) {

@@ -27,3 +38,3 @@ var msg;

var timestamp = formatter( config, data );
console.log( colors[ data.type ]( timestamp, data.namespace || "", msg ) );
console[logType[data.type]]( colors[ data.type ]( timestamp, "[" + data.namespace + "]" || "", msg ) );
},

@@ -30,0 +41,0 @@ constraint: function( data ) {

1

src/configParser.js

@@ -62,3 +62,2 @@ var _ = require( "lodash" );

} );
if ( adapter.subscriptions ) {

@@ -65,0 +64,0 @@ _.each( adapter.subscriptions, function( subscription ) {

var _ = require( "lodash" );
module.exports = function( postal, config, fount ) {
function setup( postal, config, fount ) {
config = config || {};

@@ -14,2 +15,5 @@ var log = postal.channel( config.logChannel || "log" );

return loggerFactory;
};
}
setup.log = require( "./log" )( setup );
module.exports = setup;

@@ -8,3 +8,3 @@ var util = require( "util" );

function Logger( ns, adapters ) {
this.namespace = ns || "whistlepunk";
this.namespace = ns || "";
this.adapters = adapters;

@@ -11,0 +11,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc