loglevel-mixin
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -7,2 +7,9 @@ 'use strict'; | ||
/** | ||
* @module loglevel-mixin | ||
*/ | ||
/** | ||
* default log levels | ||
*/ | ||
const defaultLogLevels = declareLevels(['trace', 'debug', 'info', 'notice', 'warn', 'error', 'crit', 'alert']); | ||
@@ -12,4 +19,4 @@ | ||
* 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. | ||
* @param {string[]} 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. | ||
*/ | ||
@@ -34,8 +41,9 @@ function declareLevels(list) { | ||
* 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 {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. | ||
* @param {object} object target where to assign properties to | ||
* @param {object} logLevels Hash with all the available loglevels. Stored by there name | ||
* @param {function} 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. | ||
* By default a method log(level,message) will be used | ||
* @return {void} | ||
*/ | ||
@@ -74,9 +82,17 @@ function defineLoggerMethods(object, logLevels = defaultLogLevels, theFunction = undefined) { | ||
/** | ||
* Declares two properties: | ||
* logLevel {String} 'info','error',... | ||
* logLevelPriority {Number} | ||
* This is method if for classes | ||
* @param {Object} properties target object where the properties will be written into | ||
* @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' | ||
* @class | ||
* @classdesc This function is a mixin for ES2015 classes. | ||
* @param {class} superclass class to be extendet | ||
* @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` | ||
* @return {class} newly created class ready to be further extendet/used | ||
* @example | ||
* ```js | ||
* import { LogLevelMixin } = from 'loglevel-mixin'; | ||
* class BaseClass { | ||
* log(level, message) { console.log(`${level} ${message}`); } | ||
* } | ||
* class LoggingEnabledClass extends LogLevelMixin(BaseClass) { | ||
* } | ||
* ``` | ||
*/ | ||
@@ -90,2 +106,5 @@ function LogLevelMixin(superclass, logLevels = defaultLogLevels, defaultLogLevel = defaultLogLevels.info) { | ||
/** | ||
* @return {string} name of the current log level | ||
*/ | ||
get logLevel() { | ||
@@ -96,4 +115,5 @@ return this._logLevel.name; | ||
/** | ||
* Set the logging level | ||
* @param {String} level | ||
* Set the logging level. | ||
* if an unknown logLEvel is given the default logLevel will be used. | ||
* @param {string} level | ||
*/ | ||
@@ -103,2 +123,6 @@ set logLevel(level) { | ||
} | ||
/** | ||
* @return {number} priority of the current log level | ||
*/ | ||
get logLevelPriority() { | ||
@@ -112,8 +136,8 @@ return this._logLevel.priority; | ||
* Declares two properties: | ||
* logLevel {String} 'info','error',... | ||
* logLevel {String} `info`,`error`,... | ||
* 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; defaults to defaultLogLevels | ||
* @param {String} defaultLogLevel the default value for the properties; defaults to 'info' | ||
* @param {object} object target where the properties will be written into | ||
* @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` | ||
*/ | ||
@@ -144,7 +168,7 @@ function defineLogLevelProperties(object, logLevels = defaultLogLevels, defaultLogLevel = defaultLogLevels.info) { | ||
/** | ||
* Aggregates values into a log event | ||
* @param {String} level | ||
* @param {String|Object} arg original log message - level and timestamp may be overwritten | ||
* @param {Object} args additional values to be merged into the final log event - values have precedence | ||
* @return {Object} suitable for log event processing | ||
* Helper function to aggregate values into a log event | ||
* @param {string} level log level | ||
* @param {string|object} arg original log message - level and timestamp may be overwritten | ||
* @param {object} args additional values to be merged into the final log event - values have precedence | ||
* @return {object} suitable for log event processing | ||
*/ | ||
@@ -151,0 +175,0 @@ function makeLogEvent(level, arg, args) { |
{ | ||
"name": "loglevel-mixin", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "mixin to declare logging methods named after a set of log levels", | ||
@@ -10,3 +10,3 @@ "main": "dist/LogLevelMixin.js", | ||
"cover": "npm run build && ./node_modules/istanbul/lib/cli.js cover --hook-run-in-context ./node_modules/mocha/bin/_mocha -- --R spec --U exports tests/*_test.js", | ||
"doc": "jsdoc src/*.js", | ||
"docs": "jsdoc2md -l off -t doc/README.hbs -f src/LogLevelMixin.js > README.md", | ||
"build": "./node_modules/rollup/bin/rollup --format=cjs --output=dist/LogLevelMixin.js -- src/LogLevelMixin.js", | ||
@@ -21,17 +21,17 @@ "test": "npm run build && mocha tests/*_test.js && markdown-doctest", | ||
"engines": { | ||
"node": ">=6.5" | ||
"node": ">=6.9.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "3.5.0", | ||
"chai": "^3.5.0", | ||
"coveralls": "2.11.14", | ||
"cracks": "3.1.2", | ||
"markdown-doctest": "^0.8.1", | ||
"cz-conventional-changelog": "1.2.0", | ||
"istanbul": "0.4.5", | ||
"jsdoc": "3.4.1", | ||
"mocha": "3.0.2", | ||
"rollup": "^0.36.0", | ||
"semantic-release": "6.3.0" | ||
"cz-conventional-changelog": "^1.2.0", | ||
"istanbul": "^0.4.5", | ||
"jsdoc-to-markdown": "^2.0.1", | ||
"markdown-doctest": "^0.9.0", | ||
"mocha": "^3.1.2", | ||
"rollup": "^0.36.1", | ||
"semantic-release": "^6.3.1" | ||
}, | ||
"_release": { | ||
"release": { | ||
"verifyRelease": "cracks" | ||
@@ -43,3 +43,2 @@ }, | ||
], | ||
"author": "Markus Felten <markus.felten@gmx.de>", | ||
"license": "BSD-2-Clause", | ||
@@ -54,3 +53,10 @@ "bugs": { | ||
} | ||
} | ||
}, | ||
"dependencies": {}, | ||
"contributors": [ | ||
{ | ||
"name": "Markus Felten", | ||
"email": "markus.felten@gmx.de" | ||
} | ||
] | ||
} |
@@ -11,4 +11,2 @@ [![npm](https://img.shields.io/npm/v/loglevel-mixin.svg)](https://www.npmjs.com/package/loglevel-mixin) | ||
[![devDependency Status](https://david-dm.org/arlac77/loglevel-mixin/dev-status.svg)](https://david-dm.org/arlac77/loglevel-mixin#info=devDependencies) | ||
[![docs](http://inch-ci.org/github/arlac77/loglevel-mixin.svg?branch=master)](http://inch-ci.org/github/arlac77/loglevel-mixin) | ||
[![API Doc](https://doclets.io/arlac77/loglevel-mixin.svg/master.svg)](https://doclets.io/arlac77/loglevel-mixin.svg/master) | ||
[![downloads](http://img.shields.io/npm/dm/loglevel-mixin.svg?style=flat-square)](https://npmjs.org/package/loglevel-mixin) | ||
@@ -51,6 +49,6 @@ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) | ||
class LoggingEnabledBaseClass extends llm.LogLevelMixin(BaseClass) { | ||
class LoggingEnabledClass extends llm.LogLevelMixin(BaseClass) { | ||
} | ||
const someObject = new LoggingEnabledBaseClass(); | ||
const someObject = new LoggingEnabledClass(); | ||
@@ -72,2 +70,66 @@ someObject.logLevel = 'error'; | ||
# API Reference | ||
- loglevel-mixin | ||
* <a name="module_loglevel-mixin..declareLevels"></a> | ||
## loglevel-mixin~declareLevels(list) ⇒ <code>object</code> | ||
Generate the loglevel objects out of a list of log level names. | ||
**Kind**: inner method of <code>[loglevel-mixin](#module_loglevel-mixin)</code> | ||
**Returns**: <code>object</code> - levels object A hash with all the loglevels. Stored by there name. | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| list | <code>Array.<string></code> | A list of log level names. The last name in the list will become the one with the highest priority. | | ||
* <a name="module_loglevel-mixin..defineLoggerMethods"></a> | ||
## loglevel-mixin~defineLoggerMethods(object, logLevels, theFunction) ⇒ <code>void</code> | ||
Adds logging methods to an existing object. | ||
For each loglevel a method with the name of the log level will be created. | ||
**Kind**: inner method of <code>[loglevel-mixin](#module_loglevel-mixin)</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| object | <code>object</code> | target where to assign properties to | | ||
| logLevels | <code>object</code> | Hash with all the available loglevels. Stored by there name | | ||
| theFunction | <code>function</code> | 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. By default a method log(level,message) will be used | | ||
* <a name="module_loglevel-mixin..defineLogLevelProperties"></a> | ||
## loglevel-mixin~defineLogLevelProperties(object, logLevels, defaultLogLevel) | ||
Declares two properties: | ||
logLevel {String} `info`,`error`,... | ||
logLevelPriority {Number} | ||
**Kind**: inner method of <code>[loglevel-mixin](#module_loglevel-mixin)</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| object | <code>object</code> | target where the properties will be written into | | ||
| logLevels | <code>object</code> | Hash with all the available loglevels. Stored by there name; defaults to defaultLogLevels | | ||
| defaultLogLevel | <code>string</code> | the default value for the properties; defaults to `info` | | ||
* <a name="module_loglevel-mixin..makeLogEvent"></a> | ||
## loglevel-mixin~makeLogEvent(level, arg, args) ⇒ <code>object</code> | ||
Helper function to aggregate values into a log event | ||
**Kind**: inner method of <code>[loglevel-mixin](#module_loglevel-mixin)</code> | ||
**Returns**: <code>object</code> - suitable for log event processing | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| level | <code>string</code> | log level | | ||
| arg | <code>string</code> | <code>object</code> | original log message - level and timestamp may be overwritten | | ||
| args | <code>object</code> | additional values to be merged into the final log event - values have precedence | | ||
* * * | ||
license | ||
@@ -74,0 +136,0 @@ ======= |
@@ -5,2 +5,9 @@ /* jslint node: true, esnext: true */ | ||
/** | ||
* @module loglevel-mixin | ||
*/ | ||
/** | ||
* default log levels | ||
*/ | ||
const defaultLogLevels = declareLevels(['trace', 'debug', 'info', 'notice', 'warn', 'error', 'crit', 'alert']); | ||
@@ -10,4 +17,4 @@ | ||
* 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. | ||
* @param {string[]} 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. | ||
*/ | ||
@@ -32,8 +39,9 @@ function declareLevels(list) { | ||
* 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 {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. | ||
* @param {object} object target where to assign properties to | ||
* @param {object} logLevels Hash with all the available loglevels. Stored by there name | ||
* @param {function} 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. | ||
* By default a method log(level,message) will be used | ||
* @return {void} | ||
*/ | ||
@@ -72,9 +80,17 @@ function defineLoggerMethods(object, logLevels = defaultLogLevels, theFunction = undefined) { | ||
/** | ||
* Declares two properties: | ||
* logLevel {String} 'info','error',... | ||
* logLevelPriority {Number} | ||
* This is method if for classes | ||
* @param {Object} properties target object where the properties will be written into | ||
* @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' | ||
* @class | ||
* @classdesc This function is a mixin for ES2015 classes. | ||
* @param {class} superclass class to be extendet | ||
* @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` | ||
* @return {class} newly created class ready to be further extendet/used | ||
* @example | ||
* ```js | ||
* import { LogLevelMixin } = from 'loglevel-mixin'; | ||
* class BaseClass { | ||
* log(level, message) { console.log(`${level} ${message}`); } | ||
* } | ||
* class LoggingEnabledClass extends LogLevelMixin(BaseClass) { | ||
* } | ||
* ``` | ||
*/ | ||
@@ -88,2 +104,5 @@ function LogLevelMixin(superclass, logLevels = defaultLogLevels, defaultLogLevel = defaultLogLevels.info) { | ||
/** | ||
* @return {string} name of the current log level | ||
*/ | ||
get logLevel() { | ||
@@ -94,4 +113,5 @@ return this._logLevel.name; | ||
/** | ||
* Set the logging level | ||
* @param {String} level | ||
* Set the logging level. | ||
* if an unknown logLEvel is given the default logLevel will be used. | ||
* @param {string} level | ||
*/ | ||
@@ -101,2 +121,6 @@ set logLevel(level) { | ||
} | ||
/** | ||
* @return {number} priority of the current log level | ||
*/ | ||
get logLevelPriority() { | ||
@@ -110,8 +134,8 @@ return this._logLevel.priority; | ||
* Declares two properties: | ||
* logLevel {String} 'info','error',... | ||
* logLevel {String} `info`,`error`,... | ||
* 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; defaults to defaultLogLevels | ||
* @param {String} defaultLogLevel the default value for the properties; defaults to 'info' | ||
* @param {object} object target where the properties will be written into | ||
* @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` | ||
*/ | ||
@@ -142,7 +166,7 @@ function defineLogLevelProperties(object, logLevels = defaultLogLevels, defaultLogLevel = defaultLogLevels.info) { | ||
/** | ||
* Aggregates values into a log event | ||
* @param {String} level | ||
* @param {String|Object} arg original log message - level and timestamp may be overwritten | ||
* @param {Object} args additional values to be merged into the final log event - values have precedence | ||
* @return {Object} suitable for log event processing | ||
* Helper function to aggregate values into a log event | ||
* @param {string} level log level | ||
* @param {string|object} arg original log message - level and timestamp may be overwritten | ||
* @param {object} args additional values to be merged into the final log event - values have precedence | ||
* @return {object} suitable for log event processing | ||
*/ | ||
@@ -149,0 +173,0 @@ function makeLogEvent(level, arg, args) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20707
351
136
0
5