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.0.0 to 1.1.0

36

LogLevelMixin.js

@@ -10,2 +10,8 @@ /* jslint node: true, esnext: true */

/**
* Generate the loglevel objects out of a list of log level names.
* @param {Array} list A list of log level names. The last name in the list will become the one with the highest priority.
* @return {Object} levels object A hash with all the loglevels. Stored by there name.
*/
function declareLevels(list) {

@@ -28,8 +34,9 @@ const levels = {};

* Adds logging methods to an existing object.
* For each loglevel a methos will be created.
* info()
* For each loglevel a method with the name of the log level will be created.
* @param {Object} target object where to assign properties tp
* @param {Function} theFunction The function to be added under the loglevel name.
* @param {Object} logLevels Hash with all the available loglevels. Stored by there name
* @param {Function, optional} theFunction The function to be added under the loglevel name.
* This function will only be called if the current loglevel is greater equal
* the log level of the called logging function
* the log level of the called logging function.
* By default a method log(leve,message) will be used
*/

@@ -47,7 +54,16 @@ exports.defineLoggerMethods = function (object, logLevels, theFunction) {

if (this.logLevelPriority >= myLevel)
theFunction(levelName, providerFunction(levelName));
if (typeof providerFunction === 'function') {
theFunction.call(this, levelName, providerFunction(levelName));
} else {
theFunction.call(this, levelName, providerFunction);
}
} : function (providerFunction) {
if (this.logLevelPriority >= myLevel)
this.log(levelName, providerFunction(levelName));
}
if (typeof providerFunction === 'function') {
this.log(levelName, providerFunction(levelName));
} else {
this.log(levelName, providerFunction);
}
},
enumerable: true
};

@@ -64,6 +80,8 @@ });

* logLevelPriority {Number}
* This is method if for classes
* @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
*/
module.exports.LogLevelMixin = (superclass, logLevels, defaultLogLevel) => class extends superclass {
exports.LogLevelMixin = (superclass, logLevels, defaultLogLevel) => class extends superclass {
constructor() {

@@ -90,3 +108,5 @@ super();

* logLevelPriority {Number}
*
* @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

@@ -93,0 +113,0 @@ */

@@ -37,3 +37,3 @@ {

"homepage": "https://github.com/arlac77/loglevel-mixin#readme",
"version": "1.0.0"
"version": "1.1.0"
}

@@ -6,2 +6,4 @@ loglevel-mixin

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.
usage

@@ -57,3 +59,3 @@ =====

```
npm install uti
npm install loglevel-mixin
```

@@ -60,0 +62,0 @@

@@ -13,3 +13,3 @@ /* global describe, it*/

describe('logging', function () {
describe('logging with classes', function () {

@@ -20,3 +20,7 @@ let theValue = 0;

class BaseClass {
class BaseClass {}
llm.defineLoggerMethods(BaseClass.prototype, llm.defaultLogLevels);
class LoggingEnabledBaseClass extends llm.LogLevelMixin(BaseClass, llm.defaultLogLevels,
llm.defaultLogLevels['info']) {
log(level, message) {

@@ -28,6 +32,2 @@ theLevel = level;

llm.defineLoggerMethods(BaseClass.prototype, llm.defaultLogLevels);
class LoggingEnabledBaseClass extends llm.LogLevelMixin(BaseClass, llm.defaultLogLevels,
llm.defaultLogLevels['info']) {}
const someObject = new LoggingEnabledBaseClass();

@@ -46,3 +46,3 @@ const someOtherObject = new LoggingEnabledBaseClass();

['trace', 'error', 'debug', 'info'].forEach(level => {
['trace', 'debug', 'error', 'notice', 'warn', 'debug', 'info'].forEach(level => {
it(`set ${level}`, function () {

@@ -49,0 +49,0 @@ someObject.logLevel = level;

@@ -18,8 +18,3 @@ /* global describe, it*/

const someObject = {
log(level, args) {
theLevel = level;
theValue = args;
}
};
const someObject = {};
const someOtherObject = {

@@ -33,3 +28,6 @@ log(level, args) {

llm.defineLoggerMethods(someObject, llm.defaultLogLevels);
llm.defineLoggerMethods(someObject, llm.defaultLogLevels, function (level, message) {
theLevel = level;
theValue = message;
});
llm.defineLogLevelProperties(someObject, llm.defaultLogLevels, llm.defaultLogLevels.info);

@@ -50,3 +48,3 @@

['trace', 'error', 'debug', 'info'].forEach(level => {
['trace', 'debug', 'error', 'notice', 'warn', 'debug', 'info'].forEach(level => {
it(`set ${level}`, function () {

@@ -53,0 +51,0 @@ someObject.logLevel = level;

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