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

loglevel-plugin-prefix

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loglevel-plugin-prefix - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

example/example.js

2

dist/loglevel-plugin-prefix.min.js

@@ -1,1 +0,1 @@

!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof module&&module.exports?module.exports=t():e.prefix=t(e)}(this,function(e){"use strict";var t,r={template:"[%t] %l:",timestampFormatter:function(e){return e.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")},levelFormatter:function(e){return e.toUpperCase()},nameFormatter:function(e){return e||"root"}},n={},o={apply:function(e,t){if(!e||!e.setLevel)throw new TypeError("Argument is not a logger");var o=!!e.getLogger,a=e.methodFactory,f=e.name||"",i=n[f]||n[""]||r;return n[f]||(e.methodFactory=function(e,t,r){var f=a(e,t,r),i=n[r||""],l=-1!==i.template.indexOf("%t"),m=-1!==i.template.indexOf("%l"),p=-1!==i.template.indexOf("%n");return function(){for(var t="",a=arguments.length,u=Array(a),c=0;c<a;c++)u[c]=arguments[c];o&&n[r]||(i.format?t+=i.format(e,r):(t+=i.template,l&&(t=t.replace(/%t/,i.timestampFormatter(new Date))),m&&(t=t.replace(/%l/,i.levelFormatter(e))),p&&(t=t.replace(/%n/,i.nameFormatter(r)))),u.length&&"string"==typeof u[0]?u[0]=t+" "+u[0]:u.unshift(t)),f.apply(void 0,u)}}),(t=t||{}).format="function"==typeof t.format?t.format:void 0,n[f]=function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(t in arguments[r])Object.prototype.hasOwnProperty.call(arguments[r],t)&&(e[t]=arguments[r][t]);return e}({},i,t),e.setLevel(e.getLevel()),e}};return e&&(t=e.prefix,o.noConflict=function(){return e.prefix===o&&(e.prefix=t),o}),o});
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof module&&module.exports?module.exports=t():e.prefix=t(e)}(this,function(e){"use strict";var t,r={template:"[%t] %l:",timestampFormatter:function(e){return e.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")},levelFormatter:function(e){return e.toUpperCase()},nameFormatter:function(e){return e||"root"}},n={},o={apply:function(e,t){if(!e||!e.setLevel)throw new TypeError("Argument is not a logger");var o=e.methodFactory,a=e.name||"",f=n[a]||n[""]||r;return n[a]||(e.methodFactory=function(e,t,r){var f=o(e,t,r),i=n[r||""]||n[""],l=-1!==i.template.indexOf("%t"),m=-1!==i.template.indexOf("%l"),p=-1!==i.template.indexOf("%n");return function(){for(var t="",o=arguments.length,u=Array(o),c=0;c<o;c++)u[c]=arguments[c];!a&&n[r]||(i.format?t+=i.format(e,r):(t+=i.template,l&&(t=t.replace(/%t/,i.timestampFormatter(new Date))),m&&(t=t.replace(/%l/,i.levelFormatter(e))),p&&(t=t.replace(/%n/,i.nameFormatter(r)))),u.length&&"string"==typeof u[0]?u[0]=t+" "+u[0]:u.unshift(t)),f.apply(void 0,u)}}),(t=t||{}).format=t.format,n[a]=function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(t in arguments[r])Object.prototype.hasOwnProperty.call(arguments[r],t)&&(e[t]=arguments[r][t]);return e}({},f,t),e.setLevel(e.getLevel()),e}};return e&&(t=e.prefix,o.noConflict=function(){return e.prefix===o&&(e.prefix=t),o}),o});

@@ -47,3 +47,2 @@ (function (root, factory) {

/* eslint-disable vars-on-top */
var isRoot = !!logger.getLogger;
var originalFactory = logger.methodFactory;

@@ -56,3 +55,3 @@ var name = logger.name || '';

var originalMethod = originalFactory(methodName, logLevel, loggerName);
var options = configs[loggerName || ''];
var options = configs[loggerName || ''] || configs[''];

@@ -73,3 +72,3 @@ var hasTimestamp = options.template.indexOf('%t') !== -1;

if (!(isRoot && configs[loggerName])) {
if (name || !configs[loggerName]) {
if (options.format) {

@@ -102,4 +101,6 @@ content += options.format(methodName, loggerName);

// for remove inherited format option if own format option not preset
config = config || {};
config.format = typeof config.format === 'function' ? config.format : undefined;
config.format = config.format;
configs[name] = merge({}, parent, config);

@@ -106,0 +107,0 @@

@@ -25,3 +25,3 @@ {

"license": "MIT",
"version": "0.7.0",
"version": "0.7.1",
"main": "./lib/loglevel-plugin-prefix",

@@ -31,2 +31,3 @@ "scripts": {

"test": "mocha",
"example": "node ./example/example.js",
"uglifyjs": "uglifyjs ./lib/loglevel-plugin-prefix.js -o ./dist/loglevel-plugin-prefix.min.js -c -m",

@@ -41,8 +42,8 @@ "build": "npm install && npm run eslint && npm run test && npm run uglifyjs"

"eslint-plugin-import": "^2.8.0",
"loglevel": "^1.6.0",
"loglevel": "^1.6.1",
"loglevel-plugin-mock": "^0.1.0",
"mocha": "^3.5.3",
"sinon": "^2.4.1",
"uglify-js": "^3.3.4"
"uglify-js": "^3.3.5"
}
}

@@ -51,13 +51,4 @@ # loglevel-plugin-prefix

Alternatively, you can use **format** option. This is a function with two arguments (level and logger), which should return a prefix string. For example,
Alternatively, you can use **format** option. This is a function with two arguments (level and logger), which should return a prefix string. If the format option is present, the other options are ignored.
```javascript
function simpleFormat(level, logger) {
return level + " (" + logger + "):";
}
```
If the format function is present, the other options are ignored.
## Usage

@@ -112,13 +103,26 @@

```javascript
var log = require('loglevel');
var prefix = require('loglevel-plugin-prefix');
const log = require('loglevel');
const prefix = require('loglevel-plugin-prefix');
log.enableAll();
prefix.apply(log, {
template: '[%t] %l (%n) static text:',
timestampFormatter: function (date) { return date.toISOString() },
levelFormatter: function (level) { return level.charAt(0).toUpperCase() + level.substr(1) },
nameFormatter: function (name) { return name || 'global' }
timestampFormatter(date) { return date.toISOString() },
levelFormatter(level) { return level.toUpperCase() },
nameFormatter(name) { return name || 'global' }
});
log.warn('prefixed message');
log.info('%s prefix', 'template');
const fn = (level, logger) => {
const timestamp = new Date().toISOString();
const label = level.toUpperCase();
const name = logger || 'global';
return `[${timestamp}] ${label} (${name}) static text:`;
};
prefix.apply(log, { format: fn });
log.info('%s prefix', 'functional');
```

@@ -128,3 +132,4 @@

```
[2017-05-29T12:53:46.000Z] Warn (global) static text: prefixed message
[2017-05-29T12:53:46.000Z] INFO (global) static text: template prefix
[2017-05-29T12:53:46.000Z] INFO (global) static text: functional prefix
```

@@ -131,0 +136,0 @@

@@ -28,4 +28,2 @@ const expect = require('chai').expect;

other.apply(loglevel, { method: spy });
const child = loglevel.getLogger('child');
child.enableAll();

@@ -36,8 +34,10 @@ beforeEach(() => {

it('Applying', () => {
it('Root applying', () => {
expect(() => prefix.apply(loglevel)).to.not.throw();
});
it('Reapplying', () => {
expect(() => prefix.apply(loglevel)).to.not.throw();
it('Root reapplyng', () => {
prefix.apply(loglevel, { template: '%l (%n):' });
loglevel.info('test');
expect(spy.calledWith('INFO (root): test')).to.be.true;
});

@@ -55,2 +55,17 @@

it('Unformat', () => {
prefix.apply(loglevel, { template: '%l:' });
loglevel.info('test');
expect(spy.calledWith('INFO: test')).to.be.true;
});
it('The prefix must be combined with the first argument, if it is a string', () => {
prefix.apply(loglevel, { template: '%l:' });
loglevel.info('foo %s', 'bar');
expect(spy.calledWith('INFO: foo %s', 'bar')).to.be.true;
});
it('All methods of the previous plugin should be called', () => {

@@ -67,3 +82,4 @@ prefix.apply(loglevel);

it('Child logger', () => {
it('Child applying', () => {
const child = loglevel.getLogger('child');
prefix.apply(child, { template: '%l (%n):' });

@@ -75,2 +91,3 @@ child.info('test');

it('Child reapplyng', () => {
const child = loglevel.getLogger('child');
prefix.apply(child, {

@@ -84,15 +101,2 @@ levelFormatter(level) {

});
it('Root reapplyng', () => {
prefix.apply(loglevel, { template: '%l (%n):' });
loglevel.info('test');
expect(spy.calledWith('INFO (root): test')).to.be.true;
});
it('The prefix must be combined with the first argument, if it is a string', () => {
prefix.apply(loglevel, { template: '%l:' });
loglevel.warn('foo %s', 'bar');
expect(spy.calledWith('WARN: foo %s', 'bar')).to.be.true;
});
});
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