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

loglevel-mixin

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loglevel-mixin - npm Package Compare versions

Comparing version 1.4.2 to 1.5.0

57

LogLevelMixin.js

@@ -5,6 +5,6 @@ /* jslint node: true, esnext: true */

const logLevels = declareLevels(['trace', 'debug', 'info', 'notice', 'warn', 'error', 'crit', 'alert']);
const defaultLogLevels = declareLevels(['trace', 'debug', 'info', 'notice', 'warn', 'error', 'crit', 'alert']);
exports.defaultLogLevels = logLevels;
exports.defaultLogLevels = defaultLogLevels;

@@ -42,3 +42,3 @@

*/
exports.defineLoggerMethods = function (object, logLevels, theFunction) {
exports.defineLoggerMethods = function (object, logLevels = defaultLogLevels, theFunction = undefined) {

@@ -51,3 +51,3 @@ const properties = {};

properties[levelName] = {
value: theFunction ?
value: theFunction !== undefined ?
function (providerFunction) {

@@ -82,26 +82,27 @@ if (this.logLevelPriority >= myLevel)

* @param {Object} properties target object where the properties will be written into
* @param {Object} logLevels Hash with all the available loglevels. Stored by there name
* @param {String} defaultLogLevel the default value for the logLevel property
* @param {Object} logLevels Object with all the available loglevels. Stored by their name; defaults to defaultLogLevels
* @param {String} defaultLogLevel the default value for the logLevel property; defaults to 'info'
*/
exports.LogLevelMixin = (superclass, logLevels, defaultLogLevel) => class extends superclass {
constructor() {
super();
this._logLevel = defaultLogLevel;
}
exports.LogLevelMixin = (superclass, logLevels = defaultLogLevels, defaultLogLevel = defaultLogLevels.info) =>
class extends superclass {
constructor() {
super();
this._logLevel = defaultLogLevel;
}
get logLevel() {
return this._logLevel.name;
}
get logLevel() {
return this._logLevel.name;
}
/**
* Set the logging level
* @param {String} level
*/
set logLevel(level) {
this._logLevel = logLevels[level] || defaultLogLevel;
}
get logLevelPriority() {
return this._logLevel.priority;
}
};
/**
* Set the logging level
* @param {String} level
*/
set logLevel(level) {
this._logLevel = logLevels[level] || defaultLogLevel;
}
get logLevelPriority() {
return this._logLevel.priority;
}
};

@@ -115,6 +116,6 @@

* @param {Object} properties target object where the properties will be written into
* @param {Object} logLevels Hash with all the available loglevels. Stored by there name
* @param {String} defaultLogLevel the default value for the properties
* @param {Object} logLevels Hash with all the available loglevels. Stored by there name; defaults to defaultLogLevels
* @param {String} defaultLogLevel the default value for the properties; defaults to 'info'
*/
exports.defineLogLevelProperties = function (object, logLevels, defaultLogLevel) {
exports.defineLogLevelProperties = function (object, logLevels = defaultLogLevels, defaultLogLevel = defaultLogLevels.info) {
const properties = {};

@@ -121,0 +122,0 @@

@@ -16,13 +16,13 @@ {

"engines": {
"node": ">=5"
"node": ">=6.5"
},
"devDependencies": {
"chai": "3.5.0",
"coveralls": "2.11.9",
"coveralls": "2.11.14",
"cracks": "3.1.2",
"cz-conventional-changelog": "1.1.6",
"istanbul": "0.4.3",
"jsdoc": "3.4.0",
"mocha": "2.4.5",
"semantic-release": "6.2.2"
"cz-conventional-changelog": "1.2.0",
"istanbul": "0.4.5",
"jsdoc": "3.4.1",
"mocha": "3.0.2",
"semantic-release": "6.3.0"
},

@@ -43,3 +43,3 @@ "keywords": [

},
"version": "1.4.2"
"version": "1.5.0"
}

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

[![npm](https://img.shields.io/npm/v/loglevel-mixin.svg)](https://www.npmjs.com/package/loglevel-mixin)

@@ -18,3 +17,3 @@ [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/arlac77/loglevel-mixin)

loglevel-mixin
====
==============

@@ -27,24 +26,20 @@ Injects methods named after a set of logLevels which are only forwarding messages if the current logLevel is higher or equal to the logLevel the name of the called method reflects.

```javascript
const llm = require(`loglevel-mixin`);
const llm = require('loglevel-mixin');
let someObject = { log(level,message) { console.log(`${level} ${message}`); } };
llm.defineLoggerMethods(someObject,
llm.defaultLogLevels);
llm.defineLogLevelProperties(someObject,
llm.defaultLogLevels,
llm.defaultLogLevels.info);
llm.defineLoggerMethods(someObject);
llm.defineLogLevelProperties(someObject);
someObject.info( level => "my info message")
someObject.logLevel = 'error';
someObject.info( level => "my info message (not reported)")
someObject.info( level => 'my info message (not reported since logLevel is error)')
someObject.logLevel = 'info';
someObject.info( level => 'my info message (reported since logLevel is now info)')
```
works for es6 classes to
------------------
works for ES2015 classes to
---------------------------
```javascript
const llm = require(`loglevel-mixin`);
const llm = require('loglevel-mixin');

@@ -55,13 +50,13 @@ class BaseClass {

llm.defineLoggerMethods(BaseClass.prototype, llm.defaultLogLevels);
class LoggingEnabledBaseClass extends llm.LogLevelMixin(BaseClass, llm.defaultLogLevels,
llm.defaultLogLevels['info']) {}
llm.defineLoggerMethods(BaseClass.prototype);
class LoggingEnabledBaseClass extends llm.LogLevelMixin(BaseClass) {
}
const someObject = new LoggingEnabledBaseClass();
someObject.info( level => "my info message")
someObject.logLevel = 'error';
someObject.info( level => "my info message (not reported)")
someObject.info( level => 'my info message (not reported since logLevel is error)')
someObject.logLevel = 'info';
someObject.info( level => 'my info message (reported since logLevel is now info)')
```

@@ -82,4 +77,1 @@

BSD-2-Clause
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/arlac77/loglevel-mixin/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
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