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

@jalik/logger

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jalik/logger - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

13

CHANGELOG.md
# Changelog
## v2.1.0
- Adds `:` after the logger name (ex: `ClassLogger: test`)
- Adds method `Logger.clone(name: String)`
- Removes useless `return` instruction in the following methods:
- `Logger.debug()`
- `Logger.error()`
- `Logger.info()`
- `Logger.warn()`
## v2.0.1
- Fixes example of `Logger.on(String, Function)` in README
- Fixes example of `Logger.on(event: String, listener: Function)` in README
## v2.0.0
- **BREAKING:** Method `Logger.on(String, Function)` has changed to improve ease of use. Before you had to pass
- **BREAKING:** Method `Logger.on(event: String, listener: Function)` has changed to improve ease of use. Before you had to pass
`debug`, `error`, `info` or `warning` as the first string argument, now use the `log`

@@ -9,0 +18,0 @@ event instead. Also in the callback, the `type` of log is inserted as the second argument after `message`, thus `context` is now the third argument.

57

dist/index.js

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

'use strict';
"use strict";

@@ -6,32 +6,33 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _logger = require('./logger');
var _logger = _interopRequireDefault(require("./logger"));
var _logger2 = _interopRequireDefault(_logger);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _logger2.default; /*
* The MIT License (MIT)
*
* Copyright (c) 2018 Karl STEIN
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 Karl STEIN
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
var _default = _logger.default;
exports.default = _default;

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

'use strict';
"use strict";

@@ -6,45 +6,23 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _extend = require("@jalik/extend");
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /*
* The MIT License (MIT)
*
* Copyright (c) 2018 Karl STEIN
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
var _observer = _interopRequireDefault(require("@jalik/observer"));
var _extend = require('@jalik/extend');
var _types = _interopRequireDefault(require("./types"));
var _observer2 = require('@jalik/observer');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _observer3 = _interopRequireDefault(_observer2);
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var _types = require('./types');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _types2 = _interopRequireDefault(_types);
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Logger = function () {
var Logger =
/*#__PURE__*/
function () {
function Logger(options) {

@@ -66,14 +44,12 @@ _classCallCheck(this, Logger);

name: null
}, options);
}, options); // Create observer
// Create observer
this.observer = new _observer3.default(this);
this.observer = new _observer.default(this); // Check console availability
// Check console availability
if ((typeof console === 'undefined' ? 'undefined' : _typeof(console)) !== 'object' || console === null) {
if ((typeof console === "undefined" ? "undefined" : _typeof(console)) !== 'object' || console === null) {
throw new Error('The console object is not available in this environment.');
}
} // Add polyfill methods to the console object
// eslint-disable-next-line no-console
// Add polyfill methods to the console object
// eslint-disable-next-line no-console
if (typeof console.log === 'function') {

@@ -84,14 +60,17 @@ // eslint-disable-next-line no-console

console.debug = console.log;
}
// eslint-disable-next-line no-console
} // eslint-disable-next-line no-console
if (typeof console.error !== 'function') {
// eslint-disable-next-line no-console
console.error = console.log;
}
// eslint-disable-next-line no-console
} // eslint-disable-next-line no-console
if (typeof console.info !== 'function') {
// eslint-disable-next-line no-console
console.info = console.log;
}
// eslint-disable-next-line no-console
} // eslint-disable-next-line no-console
if (typeof console.warn !== 'function') {

@@ -101,8 +80,8 @@ // eslint-disable-next-line no-console

}
}
} // Check logger name
// Check logger name
if (typeof this.options.name === 'undefined' || this.options.name === null) {
// Generate a name
this.name = 'logger-' + Date.now();
this.name = "logger-".concat(Date.now());
} else {

@@ -112,7 +91,6 @@ this.name = this.options.name;

}
/**
* Logs a debug message
* @param message
* @param context
* Returns a clone of the current logger with a different name.
* @param name
* @return {Logger}
*/

@@ -122,7 +100,19 @@

_createClass(Logger, [{
key: 'debug',
key: "clone",
value: function clone(name) {
return new Logger(Object.assign({}, this.options, {
name: name
}));
}
/**
* Logs a debug message
* @param message
* @param context
*/
}, {
key: "debug",
value: function debug(message, context) {
return this.log(message, _types2.default.debug, context);
this.log(message, _types.default.debug, context);
}
/**

@@ -135,3 +125,3 @@ * Logs an error message

}, {
key: 'error',
key: "error",
value: function error(messageOrError, context) {

@@ -143,3 +133,2 @@ var ctx = context || {};

ctx.error = {};
var attributes = ['name', 'message', 'reason', 'stack', 'type'];

@@ -152,9 +141,9 @@

}
var message = messageOrError.message;
msg = message;
}
return this.log(msg, _types2.default.error, ctx);
this.log(msg, _types.default.error, ctx);
}
/**

@@ -166,7 +155,6 @@ * Returns the logger name

}, {
key: 'getName',
key: "getName",
value: function getName() {
return this.name;
}
/**

@@ -179,7 +167,6 @@ * Logs an information message

}, {
key: 'info',
key: "info",
value: function info(message, context) {
return this.log(message, _types2.default.info, context);
this.log(message, _types.default.info, context);
}
/**

@@ -191,7 +178,6 @@ * Checks if the logger is active

}, {
key: 'isActive',
key: "isActive",
value: function isActive() {
return this.options.active === true;
}
/**

@@ -205,25 +191,23 @@ * Logs a message

}, {
key: 'log',
key: "log",
value: function log(message, type, context) {
var _observer;
var _this$observer;
if (this.isActive()) {
var args = [];
var args = []; // Display logger name in console
// Display logger name in console
if (this.options.displayName === true) {
args.push(this.name);
}
args.push("".concat(this.name, ":"));
} // Display message in console
// Display message in console
args.push(message);
// Display context in console
args.push(message); // Display context in console
if (typeof context !== 'undefined' && this.options.displayContext === true) {
args.push(context);
}
} // Displays the message in the console
// Displays the message in the console
switch (type) {
case _types2.default.debug:
case _types.default.debug:
if (this.options.console.debug === true) {

@@ -233,5 +217,6 @@ // eslint-disable-next-line no-console

}
break;
case _types2.default.error:
case _types.default.error:
if (this.options.console.error === true) {

@@ -241,5 +226,6 @@ // eslint-disable-next-line no-console

}
break;
case _types2.default.info:
case _types.default.info:
if (this.options.console.info === true) {

@@ -249,5 +235,6 @@ // eslint-disable-next-line no-console

}
break;
case _types2.default.warning:
case _types.default.warning:
if (this.options.console.warning === true) {

@@ -257,2 +244,3 @@ // eslint-disable-next-line no-console

}
break;

@@ -265,33 +253,31 @@

}
}
}
} // Notify all listeners
// Notify all listeners
(_observer = this.observer).notify.apply(_observer, ['log'].concat([message, type, context]));
(_this$observer = this.observer).notify.apply(_this$observer, ['log'].concat([message, type, context]));
}
/**
* Removes an event listener
* @param event
* @param callback
* @param listener
*/
}, {
key: 'off',
value: function off(event, callback) {
this.observer.detach(event, callback);
key: "off",
value: function off(event, listener) {
this.observer.detach(event, listener);
}
/**
* Adds an event listener
* @param event
* @param callback
* @param listener
*/
}, {
key: 'on',
value: function on(event, callback) {
this.observer.attach(event, callback);
key: "on",
value: function on(event, listener) {
this.observer.attach(event, listener);
}
/**

@@ -303,7 +289,6 @@ * Activates or deactivates the logger

}, {
key: 'setActive',
key: "setActive",
value: function setActive(active) {
this.options.active = active === true;
}
/**

@@ -316,5 +301,5 @@ * Logs a warning message

}, {
key: 'warn',
key: "warn",
value: function warn(message, context) {
return this.log(message, _types2.default.warning, context);
this.log(message, _types.default.warning, context);
}

@@ -326,2 +311,3 @@ }]);

exports.default = Logger;
var _default = Logger;
exports.default = _default;

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

'use strict';
"use strict";

@@ -6,2 +6,4 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
/*

@@ -31,4 +33,3 @@ * The MIT License (MIT)

*/
exports.default = {
var _default = {
/**

@@ -38,2 +39,3 @@ * Debug

debug: 'debug',
/**

@@ -43,2 +45,3 @@ * Error

error: 'error',
/**

@@ -48,2 +51,3 @@ * Information

info: 'info',
/**

@@ -53,2 +57,3 @@ * Warning

warning: 'warning'
};
};
exports.default = _default;
{
"name": "@jalik/logger",
"version": "2.0.1",
"version": "2.1.0",
"description": "A logging utility to log messages to anywhere.",

@@ -26,10 +26,9 @@ "license": "MIT",

"scripts": {
"build": "./node_modules/.bin/gulp build",
"bundle": "./node_modules/.bin/webpack -p",
"lint": "./node_modules/.bin/eslint .",
"lint-fix": "./node_modules/.bin/eslint --fix .",
"prepare": "./node_modules/.bin/gulp prepare",
"build": "npx gulp build",
"lint": "npx eslint .",
"lint-fix": "npx eslint --fix .",
"prepare": "npx gulp prepare",
"prepublishOnly": "npm test",
"test": "./node_modules/.bin/jest",
"watch": "./node_modules/.bin/gulp watch"
"test": "npx jest",
"watch": "npx gulp watch"
},

@@ -41,22 +40,18 @@ "dependencies": {

"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"ajv": "^6.5.4",
"babel-core": "^7.0.0-bridge.0",
"del": "^3.0.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.9.1",
"eslint": "^5.6.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^21.24.1",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"gulp": "^4.0.0",
"gulp-babel": "^7.0.1",
"gulp-eslint": "^4.0.2",
"gulp-strip-comments": "^2.5.2",
"gulp-watch": "^5.0.0",
"jest": "^23.1.0",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.3"
"gulp-babel": "^8.0.0",
"gulp-eslint": "^5.0.0",
"jest": "^23.6.0"
}
}

@@ -136,2 +136,16 @@ # Logger

## Cloning a logger
It can be useful to clone an existing logger, thus reusing the same configuration by calling the `clone()` method on a logger.
```js
import Logger from '@jalik/logger';
const loggerA = new Logger({name:'A', displayContext: true});
const loggerB = loggerA.clone('B');
// The logger B will display the given context since it has been enabled in the logger A.
loggerB.debug('printed now', {date: new Date()});
```
## Changelog

@@ -138,0 +152,0 @@

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