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

106

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

106 - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

73

lib/index.js

@@ -21,2 +21,49 @@ "use strict";

var transports = [ ];
function shouldLog( level, highest )
{
if ( highest === 'disabled' )
return false;
if (
levels.hasOwnProperty( level ) &&
levels[ level ] > levels[ highest ]
)
return false;
return true;
}
function addTransport( fn, opts )
{
opts = opts || { };
transports.push( function( level, args )
{
var highestLevel = opts.level || exporter.level;
if ( !shouldLog( level, highestLevel ) )
return;
args = [ ].slice.call( args );
var extra = args.pop( );
var internal = extra.internal;
var data = {
level : level,
messages : args,
meta : extra.meta || null,
prefix : internal.prefix,
sequence : internal.sequence,
sequenceDirection : internal.sequenceDirection,
time : internal.time,
timestamp : internal.timestamp
};
fn( data );
} );
}
function log( prefix )

@@ -31,9 +78,6 @@ {

if (
exporter.level === 'disabled'
||
(
levels.hasOwnProperty( level )
&& levels[ level ] > levels[ exporter.level ]
)
transports.length === 0 &&
!shouldLog( level, exporter.level )
)
// Too high log level, and no other transports
return;

@@ -140,3 +184,9 @@

return logger.apply( logger, args );
transports.forEach( function( transport )
{
transport( level, args );
} );
if ( shouldLog( level, exporter.level ) )
return logger.apply( logger, args );
}

@@ -157,8 +207,9 @@ }

var exporter = log;
exporter.level = 'debug';
exporter.Sequencer = Sequencer;
exporter.Sequence = Sequence;
exporter.colors = true;
exporter.level = 'debug';
exporter.Sequencer = Sequencer;
exporter.Sequence = Sequence;
exporter.colors = true;
exporter.addTransport = addTransport;
return exporter;
};

2

package.json

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "1.0.5",
"version": "1.1.0",
"author": "Gustaf Räntilä <g.rantila@gmail.com>",

@@ -8,0 +8,0 @@ "repository": {

@@ -18,2 +18,4 @@ # 106

You also have the possibility to add your own custom transports (e.g. to automatically send log errors from the browser to the server).
# API

@@ -89,1 +91,30 @@

The above will be colored, and each sequence will get its own color (circulating between a few pre-defined colors). Again, this applies to node.js as well as browsers!
## Custom transports
To add a custom transport, you create your own callback function, and call `addTransport( )` on the logger. You can also set your own log-level using the second (optional) argument, so that this transport only get certain logs.
```js
var logger = require( '106' );
var log = logger( 'foo' );
function customTransport( logData )
{
logData.level; // The log level, 'info', 'warn', etc
logData.messages; // The message parts (as an array)
logData.meta; // The last argument to log() if it's an
// object or array, and not covered by a '%s'.
logData.prefix; // The prefix ('foo' in this example)
logData.sequence; // The sequence (or null)
logData.sequenceDirection; // The sequence direction (or null)
logData.time; // The time (as a javascript Date object)
logData.timestamp; // The time as an ISO-formatted string
}
// Forward error logs to "customTransport"
logger.addTransport( customTransport, { level: 'warn' } );
log.error( "This will be sent to the custom logger" );
log.warn( "And this" );
log.info( "But this won't" );
```
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