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 3.0.3 to 3.0.4

dist/util.js

7

dist/index.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -58,11 +56,6 @@ value: true

});
var _levels = _interopRequireWildcard(require("./levels"));
var _Logger = _interopRequireDefault(require("./Logger"));
var _consoleOutput = _interopRequireDefault(require("./outputs/consoleOutput"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

4

dist/levels.js

@@ -7,3 +7,2 @@ "use strict";

exports["default"] = exports.WARN = exports.INFO = exports.FATAL = exports.ERROR = exports.DEBUG = void 0;
/*

@@ -13,2 +12,3 @@ * The MIT License (MIT)

*/
var DEBUG = 'debug';

@@ -23,2 +23,3 @@ exports.DEBUG = DEBUG;

var WARN = 'warn';
/**

@@ -28,3 +29,2 @@ * Log levels ordered by importance and granularity (less to most).

*/
exports.WARN = WARN;

@@ -31,0 +31,0 @@ var levels = [DEBUG, INFO, WARN, ERROR, FATAL];

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof3 = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -11,23 +9,13 @@ value: true

exports["default"] = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _levels = _interopRequireWildcard(require("./levels"));
var _consoleOutput = _interopRequireDefault(require("./outputs/consoleOutput"));
var _util = require("./util");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var defaultOptions = {

@@ -41,21 +29,2 @@ active: true,

};
/**
* Returns details of an error.
* @param {Error} error
* @return {{message: string, name: string, reason: string, stack: string, type: string}}
*/
function getErrorDetails(error) {
var attributes = ['message', 'name', 'reason', 'stack', 'type'];
var details = {};
for (var i = 0; i < attributes.length; i += 1) {
if (attributes[i] in error) {
details[attributes[i]] = error[attributes[i]];
}
}
return details;
}
var Logger = /*#__PURE__*/function () {

@@ -65,19 +34,22 @@ function Logger() {

(0, _classCallCheck2["default"])(this, Logger);
// Use default options.
var opts = _objectSpread(_objectSpread({}, defaultOptions), options); // Set logger status.
var opts = _objectSpread(_objectSpread({}, defaultOptions), options);
// Set logger status.
this.active = opts.active === true;
this.active = opts.active === true; // Set default log context.
// Set default log context.
this.defaultContext = opts.defaultContext;
this.defaultContext = opts.defaultContext; // Set logs filter.
// Set logs filter.
this.filter = opts.filter;
this.filter = opts.filter; // Set minimal log level.
// Set minimal log level.
this.level = opts.level;
this.level = opts.level; // Set logger name.
// Set logger name.
this.name = opts.name == null ? "logger_".concat(Date.now()) : String(opts.name);
this.name = opts.name == null ? "logger_".concat(Date.now()) : String(opts.name); // Set log outputs.
// Set log outputs.
this.outputs = [].concat(opts.outputs || []);
if ((0, _typeof2["default"])(this.outputs) !== 'object' || !(this.outputs instanceof Array) || this.outputs.length === 0) {

@@ -87,2 +59,3 @@ throw new Error('Logger outputs cannot be empty.');

}
/**

@@ -93,4 +66,2 @@ * Logs a debug message.

*/
(0, _createClass2["default"])(Logger, [{

@@ -102,2 +73,3 @@ key: "debug",

}
/**

@@ -108,3 +80,2 @@ * Logs an error message.

*/
}, {

@@ -116,10 +87,9 @@ key: "error",

var message = messageOrError;
if (messageOrError instanceof Error) {
message = messageOrError.message;
ctx.error = getErrorDetails(messageOrError);
ctx.error = (0, _util.getErrorDetails)(messageOrError);
}
this.log(_levels.ERROR, message, ctx);
}
/**

@@ -130,3 +100,2 @@ * Logs a fatal error message.

*/
}, {

@@ -138,10 +107,9 @@ key: "fatal",

var message = messageOrError;
if (messageOrError instanceof Error) {
message = messageOrError.message;
ctx.error = getErrorDetails(messageOrError);
ctx.error = (0, _util.getErrorDetails)(messageOrError);
}
this.log(_levels.FATAL, message, ctx);
}
/**

@@ -151,3 +119,2 @@ * Returns the log level.

*/
}, {

@@ -158,2 +125,3 @@ key: "getLevel",

}
/**

@@ -163,3 +131,2 @@ * Returns the logger name.

*/
}, {

@@ -170,2 +137,3 @@ key: "getName",

}
/**

@@ -176,3 +144,2 @@ * Logs an informational message.

*/
}, {

@@ -184,2 +151,3 @@ key: "info",

}
/**

@@ -189,3 +157,2 @@ * Checks if the logging is active.

*/
}, {

@@ -196,2 +163,3 @@ key: "isActive",

}
/**

@@ -203,3 +171,2 @@ * Logs a message with a certain level.

*/
}, {

@@ -209,9 +176,8 @@ key: "log",

var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
// Ignore if logger is not active or if log level is higher.
if (!this.isActive() || _levels["default"].indexOf(this.level) > _levels["default"].indexOf(level)) {
return;
} // Prepare log event.
}
// Prepare log event.
var event = {

@@ -223,9 +189,10 @@ context: this.defaultContext ? _objectSpread(_objectSpread({}, this.defaultContext), context) : context,

timestamp: Date.now()
}; // Filter log event.
};
// Filter log event.
if (typeof this.filter === 'function' && this.filter(event) !== true) {
return;
} // Pass log event to outputs.
}
// Pass log event to outputs.
this.outputs.forEach(function (output) {

@@ -235,2 +202,3 @@ output(event);

}
/**

@@ -240,3 +208,2 @@ * Enables or disables logging.

*/
}, {

@@ -247,2 +214,3 @@ key: "setActive",

}
/**

@@ -252,3 +220,2 @@ * Changes the log level.

*/
}, {

@@ -259,2 +226,3 @@ key: "setLevel",

}
/**

@@ -265,3 +233,2 @@ * Logs a warning message.

*/
}, {

@@ -276,4 +243,3 @@ key: "warn",

}();
var _default = Logger;
exports["default"] = _default;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,50 +8,48 @@ value: true

exports["default"] = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _levels = require("../levels");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var debug = typeof console.debug === 'function' ? console.debug : console.log;
var error = typeof console.error === 'function' ? console.error : console.log;
var fatal = typeof console.fatal === 'function' ? console.fatal : error;
var info = typeof console.info === 'function' ? console.info : console.log;
var warn = typeof console.warn === 'function' ? console.info : console.log;
var defaultOptions = {
formatter: function formatter(event) {
var context = event.context,
level = event.level,
logger = event.logger,
message = event.message,
timestamp = event.timestamp;
var out = "".concat(new Date(timestamp).toISOString(), " ").concat(level.toUpperCase(), " [").concat(logger, "] : ").concat(message);
if (context) {
out += " ; ".concat(JSON.stringify(context));
}
return out;
function defaultFormatter(event) {
var context = event.context,
level = event.level,
logger = event.logger,
message = event.message,
timestamp = event.timestamp;
var out = "".concat(new Date(timestamp).toISOString(), " ").concat(level.toUpperCase(), " [").concat(logger, "] : ").concat(message);
if (context) {
out += " ; ".concat(JSON.stringify(context));
}
};
return out;
}
/**
* Logs events to console.
* @param options
* @returns {(function(*): void)|*}
*/
function consoleOutput() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultOptions;
var opts = _objectSpread(_objectSpread({}, defaultOptions), options);
var formatter = opts.formatter;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
var opts = _objectSpread({
formatter: defaultFormatter
}, options);
var entries = opts.entries,
formatter = opts.formatter;
var harvest = function harvest(message) {
entries.push(message);
};
var debug = entries ? harvest : console.debug || console.log;
var error = entries ? harvest : console.error || console.log;
var fatal = entries ? harvest : console.fatal || console.log;
var info = entries ? harvest : console.info || console.log;
var warn = entries ? harvest : console.warn || console.log;
return function (event) {
var level = event.level; // Prepare output.
var level = event.level;
// Prepare output.
var output = formatter(event);
if (!(output instanceof Array)) {
output = [output];
}
if (level === _levels.DEBUG) {

@@ -71,4 +68,3 @@ debug.apply(void 0, (0, _toConsumableArray2["default"])(output));

}
var _default = consoleOutput;
exports["default"] = _default;

@@ -7,2 +7,3 @@ "use strict";

*/
// Add polyfill methods to the console object

@@ -15,17 +16,14 @@ // eslint-disable-next-line no-console

console.debug = console.log.bind(console);
} // 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.bind(console);
} // 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.bind(console);
} // eslint-disable-next-line no-console
}
// eslint-disable-next-line no-console
if (typeof console.warn !== 'function') {

@@ -32,0 +30,0 @@ // eslint-disable-next-line no-console

{
"name": "@jalik/logger",
"version": "3.0.3",
"version": "3.0.4",
"description": "A logging utility to log messages to anywhere.",

@@ -38,3 +38,3 @@ "license": "MIT",

"prepublishOnly": "npm test",
"test": "jest --passWithNoTests"
"test": "jest --passWithNoTests --coverage=true"
},

@@ -46,16 +46,17 @@ "files": [

"dependencies": {
"@babel/runtime": "^7.17.2"
"@babel/runtime": "^7.19.4",
"@jest/globals": "^29.2.1"
},
"devDependencies": {
"@babel/cli": "^7.17.3",
"@babel/core": "^7.17.5",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"eslint": "^8.9.0",
"@babel/cli": "^7.19.3",
"@babel/core": "^7.19.3",
"@babel/plugin-transform-runtime": "^7.19.1",
"@babel/preset-env": "^7.19.4",
"eslint": "^8.25.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.1",
"jest": "^27.5.1",
"typescript": "^4.5.5"
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.3",
"jest": "^29.2.1",
"typescript": "^4.8.4"
}
}
# @jalik/logger
![GitHub package.json version](https://img.shields.io/github/package-json/v/jalik/js-logger.svg)
[![Build Status](https://travis-ci.com/jalik/js-logger.svg?branch=master)](https://travis-ci.com/jalik/js-logger)
![GitHub](https://img.shields.io/github/license/jalik/js-logger.svg)
![GitHub last commit](https://img.shields.io/github/last-commit/jalik/js-logger.svg)
![Last commit](https://img.shields.io/github/last-commit/jalik/js-logger.svg)
![Build Status](https://github.com/jalik/js-logger/actions/workflows/node.js.yml/badge.svg)
[![GitHub issues](https://img.shields.io/github/issues/jalik/js-logger.svg)](https://github.com/jalik/js-logger/issues)

@@ -8,0 +8,0 @@ ![npm](https://img.shields.io/npm/dt/@jalik/logger.svg)

/*
* The MIT License (MIT)
* Copyright (c) 2021 Karl STEIN
* Copyright (c) 2022 Karl STEIN
*/

@@ -14,2 +14,3 @@

import consoleOutput from './outputs/consoleOutput';
import { getErrorDetails } from './util';

@@ -25,19 +26,2 @@ const defaultOptions = {

/**
* Returns details of an error.
* @param {Error} error
* @return {{message: string, name: string, reason: string, stack: string, type: string}}
*/
function getErrorDetails(error) {
const attributes = ['message', 'name', 'reason', 'stack', 'type'];
const details = {};
for (let i = 0; i < attributes.length; i += 1) {
if (attributes[i] in error) {
details[attributes[i]] = error[attributes[i]];
}
}
return details;
}
class Logger {

@@ -44,0 +28,0 @@ constructor(options = {}) {

/*
* The MIT License (MIT)
* Copyright (c) 2021 Karl STEIN
* Copyright (c) 2022 Karl STEIN
*/

@@ -16,30 +16,38 @@

const debug = typeof console.debug === 'function' ? console.debug : console.log;
const error = typeof console.error === 'function' ? console.error : console.log;
const fatal = typeof console.fatal === 'function' ? console.fatal : error;
const info = typeof console.info === 'function' ? console.info : console.log;
const warn = typeof console.warn === 'function' ? console.info : console.log;
function defaultFormatter(event) {
const {
context,
level,
logger,
message,
timestamp,
} = event;
const defaultOptions = {
formatter: (event) => {
const {
context,
level,
logger,
message,
timestamp,
} = event;
let out = `${new Date(timestamp).toISOString()} ${level.toUpperCase()} [${logger}] : ${message}`;
let out = `${new Date(timestamp).toISOString()} ${level.toUpperCase()} [${logger}] : ${message}`;
if (context) {
out += ` ; ${JSON.stringify(context)}`;
}
return out;
},
};
if (context) {
out += ` ; ${JSON.stringify(context)}`;
}
return out;
}
function consoleOutput(options = defaultOptions) {
const opts = { ...defaultOptions, ...options };
const { formatter } = opts;
/**
* Logs events to console.
* @param options
* @returns {(function(*): void)|*}
*/
function consoleOutput(options = undefined) {
const opts = { formatter: defaultFormatter, ...options };
const { entries, formatter } = opts;
const harvest = (message) => {
entries.push(message);
};
const debug = entries ? harvest : console.debug || console.log;
const error = entries ? harvest : console.error || console.log;
const fatal = entries ? harvest : console.fatal || console.log;
const info = entries ? harvest : console.info || console.log;
const warn = entries ? harvest : console.warn || console.log;
return (event) => {

@@ -46,0 +54,0 @@ const { level } = event;

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