Socket
Socket
Sign inDemoInstall

console-log-level

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-log-level - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

11

index.js
'use strict';
var util = require('util');
var levels = ['debug', 'info', 'warn', 'error', 'fatal'];

@@ -18,2 +20,5 @@

if (!shouldLog(level)) return;
var prefix = opts.prefix;
switch (level) {

@@ -23,2 +28,8 @@ case 'debug': level = 'info'; break;

}
if (prefix) {
if (typeof prefix === 'function') prefix = prefix();
arguments[0] = util.format(prefix, arguments[0]);
}
console[level].apply(console, arguments);

@@ -25,0 +36,0 @@ };

8

package.json
{
"name": "console-log-level",
"version": "1.0.0",
"version": "1.1.0",
"description": "The most simple logger imaginable",

@@ -31,3 +31,7 @@ "main": "index.js",

"tape": "^3.0.3"
}
},
"coordinates": [
55.687684,
12.5955911
]
}

@@ -7,4 +7,3 @@ # console-log-level

Log levels supported: debug, info, warn, error and fatal (defaults to
'info').
Log levels supported: debug, info, warn, error and fatal.

@@ -31,4 +30,24 @@ [![build status](https://secure.travis-ci.org/watson/console-log-level.png)](http://travis-ci.org/watson/console-log-level)

## Options
Configure the logger by passing an options object:
```js
var log = require('console-log-level')({
prefix: function () { return new Date().toISOString(); },
level: 'info'
});
```
### level
A `string` to specify the log level. Defaults to `info`.
### prefix
Specify this option if you want to set a prefix for all log messages.
This must be a `string` or a `function` that returns a string.
## License
MIT

@@ -25,2 +25,14 @@ 'use strict';

var spyOn = function (method, spy) {
console['~' + method] = console[method];
console[method] = function () {
spy.apply(console, arguments);
};
};
var spyOff = function (method) {
console[method] = console['~' + method];
delete console['~' + method];
};
test('log all', function (t) {

@@ -106,1 +118,59 @@ var logger = Logger({ level: 'debug' });

});
test('set prefix', function (t) {
var now = new Date().toISOString();
var logger = Logger({ prefix: now });
var msg = 'bar';
spyOn('info', function () {
spyOff('info');
t.equal(arguments[0], now + ' foo %s', 'first arg ok');
t.equal(arguments[1], msg, 'second arg ok');
});
spyOn('warn', function () {
spyOff('warn');
t.equal(arguments[0], now + ' foo %s', 'first arg ok');
t.equal(arguments[1], msg, 'second arg ok');
});
spyOn('error', function () {
spyOff('error');
t.equal(arguments[0], now + ' foo %s', 'first arg ok');
t.equal(arguments[1], msg, 'second arg ok');
t.end();
});
logger.info('foo %s', msg);
logger.warn('foo %s', msg);
logger.error('foo %s', msg);
});
test('set prefix with function', function (t) {
var now = new Date().toISOString();
var logger = Logger({ prefix: function () { return now; } });
var msg = 'bar';
spyOn('info', function () {
spyOff('info');
t.equal(arguments[0], now + ' foo %s', 'first arg ok');
t.equal(arguments[1], msg, 'second arg ok');
});
spyOn('warn', function () {
spyOff('warn');
t.equal(arguments[0], now + ' foo %s', 'first arg ok');
t.equal(arguments[1], msg, 'second arg ok');
});
spyOn('error', function () {
spyOff('error');
t.equal(arguments[0], now + ' foo %s', 'first arg ok');
t.equal(arguments[1], msg, 'second arg ok');
t.end();
});
logger.info('foo %s', msg);
logger.warn('foo %s', msg);
logger.error('foo %s', msg);
});

Sorry, the diff of this file is not supported yet

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