Socket
Socket
Sign inDemoInstall

@stencila/logga

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stencila/logga - npm Package Compare versions

Comparing version 1.4.1 to 2.0.0

19

CHANGELOG.md

@@ -0,1 +1,20 @@

# [2.0.0](https://github.com/stencila/logga/compare/v1.4.1...v2.0.0) (2019-11-21)
### Code Refactoring
* **defaultHandler:** Change option name to `maxLevel` ([ca22dec](https://github.com/stencila/logga/commit/ca22dec84c3282369d974deaa311e884f85f8ef7))
### Features
* **addHandler:** Allow log event filters to be specified ([0f467b4](https://github.com/stencila/logga/commit/0f467b47676d62b0238b66f31238f1db4024dfd0))
* **addHandler:** Return the handler that was added. ([322c7d1](https://github.com/stencila/logga/commit/322c7d187ff190fb8841619b00bbb3b1a21d8984))
### BREAKING CHANGES
* **defaultHandler:** Made because `level` had caused some confusion amongst users of this library and to be consistent with the same option in `addHandler`.
* **addHandler:** Handler funtion is no longer optional for either `addHandler` or `removeHandler`. Used to default to `defaultHandler`.
## [1.4.1](https://github.com/stencila/logga/compare/v1.4.0...v1.4.1) (2019-11-10)

@@ -2,0 +21,0 @@

2

dist/browser/index.js

@@ -6,4 +6,4 @@ parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"g5IB":[function(require,module,exports) {

var process = require("process");
var e=require("process");function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var t=this&&this.__assign||function(){return(t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)},n=this&&this.__spreadArrays||function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;var n=Array(e),o=0;for(r=0;r<t;r++)for(var i=arguments[r],s=0,a=i.length;s<a;s++,o++)n[o]=i[s];return n};Object.defineProperty(exports,"__esModule",{value:!0});var o,i,s="stencila:logga";if(void 0!==e&&(o={emit:e.emit,listeners:e.listeners,addListener:e.addListener,removeListener:e.removeListener,removeAllListeners:e.removeAllListeners}),"undefined"!=typeof window){var a=new Map;o={emit:function(e,r){window.dispatchEvent(new CustomEvent(e,{detail:r}))},listeners:function(){return Array.from(a.keys())},addListener:function(e,r){var t=function(e){return r(e.detail)};window.addEventListener(e,t),a.set(r,t)},removeListener:function(e,r){var t=a.get(r);void 0!==t&&(window.removeEventListener(e,t),a.delete(r))},removeAllListeners:function(e){Array.from(a.values()).map(function(r){window.removeEventListener(e,r)}),a.clear()}}}function l(e,t,a){var l="";"object"===r(e)&&void 0!==e.message?l=e.message:"string"==typeof e&&(l=e);var v={tag:t,level:a,message:l};if("object"===r(e)&&void 0!==e.stack)v.stack=e.stack;else if(a<=i.error){var d=new Error;if(void 0!==d.stack){var f=d.stack.split("\n");v.stack=n([f[0]],f.slice(3)).join("\n")}}o.emit(s,v)}function v(){return o.listeners(s)}function d(e){o.addListener(s,void 0!==e?e:p)}function f(e){o.removeListener(s,void 0!==e?e:p)}function u(){o.removeAllListeners(s)}function c(e){u(),d(e)}!function(e){e[e.error=0]="error",e[e.warn=1]="warn",e[e.info=2]="info",e[e.debug=3]="debug"}(i=exports.LogLevel||(exports.LogLevel={})),exports.handlers=v,exports.addHandler=d,exports.removeHandler=f,exports.removeHandlers=u,exports.replaceHandlers=c;var m=new Map;function p(r,n){var o=r.tag,s=r.level,a=r.message,l=r.stack;if(!(s>(void 0!==n&&void 0!==n.level?n.level:i.info))){var v=void 0!==n?n.throttle:void 0;if(void 0!==v){var d=(void 0!==v.signature?v.signature:"").replace(/\${tag}/,o).replace(/\${level}/,s.toString()).replace(/\${message}/,a),f=m.get(d);if(void 0!==f){var u=void 0!==v.duration?v.duration:1e3;if(Date.now()-f<u)return}m.set(d,Date.now())}var c="";if(void 0!==e&&void 0!==e.stderr&&!0!==e.stderr.isTTY)c=JSON.stringify(t({time:(new Date).toISOString()},r));else{var p=s<0?0:s>3?3:s,g=i[p].toUpperCase().padEnd(5," ");if("undefined"!=typeof window)c=g+" "+o+" "+a;else{c=["🚨","⚠","🛈","🐛"][p]+" "+["","","",""][p]+g+" "+o+" "+a}void 0!==l&&(c+="\n "+l)}console.error(c)}}function g(e){return{error:function(r){l(r,e,i.error)},warn:function(r){l(r,e,i.warn)},info:function(r){l(r,e,i.info)},debug:function(r){l(r,e,i.debug)}}}exports.defaultHandler=p,0===v().length&&d(p),exports.getLogger=g;
var e=require("process");function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var t=this&&this.__assign||function(){return(t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)},n=this&&this.__spreadArrays||function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;var n=Array(e),o=0;for(r=0;r<t;r++)for(var i=arguments[r],s=0,a=i.length;s<a;s++,o++)n[o]=i[s];return n};Object.defineProperty(exports,"__esModule",{value:!0});var o,i,s="stencila:logga";if(void 0!==e&&(o={emit:e.emit,listeners:e.listeners,addListener:e.addListener,removeListener:e.removeListener,removeAllListeners:e.removeAllListeners}),"undefined"!=typeof window){var a=new Map;o={emit:function(e,r){window.dispatchEvent(new CustomEvent(e,{detail:r}))},listeners:function(){return Array.from(a.keys())},addListener:function(e,r){var t=function(e){return r(e.detail)};window.addEventListener(e,t),a.set(r,t)},removeListener:function(e,r){var t=a.get(r);void 0!==t&&(window.removeEventListener(e,t),a.delete(r))},removeAllListeners:function(e){Array.from(a.values()).map(function(r){window.removeEventListener(e,r)}),a.clear()}}}function v(e,t,a){var v="";"object"===r(e)&&void 0!==e.message?v=e.message:"string"==typeof e&&(v=e);var d={tag:t,level:a,message:v};if("object"===r(e)&&void 0!==e.stack)d.stack=e.stack;else if(a<=i.error){var l=new Error;if(void 0!==l.stack){var f=l.stack.split("\n");d.stack=n([f[0]],f.slice(3)).join("\n")}}o.emit(s,d)}function d(){return o.listeners(s)}function l(e,r){void 0===r&&(r={});var t=e,n=r.tags,i=r.maxLevel,a=r.messageRegex,v=r.func;return void 0===n&&void 0===i&&void 0===a&&void 0===v||(t=function(r){(void 0===n||n.includes(r.tag))&&(void 0!==i&&r.level>i||(void 0===a||a.test(r.message))&&(void 0===v||v(r))&&e(r))}),o.addListener(s,t),t}function f(e){o.removeListener(s,e)}function u(){o.removeAllListeners(s)}function c(e){u(),l(e)}!function(e){e[e.error=0]="error",e[e.warn=1]="warn",e[e.info=2]="info",e[e.debug=3]="debug"}(i=exports.LogLevel||(exports.LogLevel={})),exports.handlers=d,exports.addHandler=l,exports.removeHandler=f,exports.removeHandlers=u,exports.replaceHandlers=c;var m=new Map;function p(r,n){var o=r.tag,s=r.level,a=r.message,v=r.stack;if(!(s>(void 0!==n&&void 0!==n.maxLevel?n.maxLevel:i.info))){var d=void 0!==n?n.throttle:void 0;if(void 0!==d){var l=(void 0!==d.signature?d.signature:"").replace(/\${tag}/,o).replace(/\${level}/,s.toString()).replace(/\${message}/,a),f=m.get(l);if(void 0!==f){var u=void 0!==d.duration?d.duration:1e3;if(Date.now()-f<u)return}m.set(l,Date.now())}var c="";if(void 0!==e&&void 0!==e.stderr&&!0!==e.stderr.isTTY)c=JSON.stringify(t({time:(new Date).toISOString()},r));else{var p=s<0?0:s>3?3:s,g=i[p].toUpperCase().padEnd(5," ");if("undefined"!=typeof window)c=g+" "+o+" "+a;else{c=["🚨","⚠","🛈","🐛"][p]+" "+["","","",""][p]+g+" "+o+" "+a}void 0!==v&&(c+="\n "+v)}console.error(c)}}function g(e){return{error:function(r){v(r,e,i.error)},warn:function(r){v(r,e,i.warn)},info:function(r){v(r,e,i.info)},debug:function(r){v(r,e,i.debug)}}}exports.defaultHandler=p,0===d().length&&l(p),exports.getLogger=g;
},{"process":"g5IB"}]},{},["QCba"], "logga")
//# sourceMappingURL=/index.js.map

@@ -30,13 +30,22 @@ export declare enum LogLevel {

*
* @param handler A function that handles the log data
* @param handler A function that handles the log data.
* @param filter Options for filtering log data prior to sending to the handler.
* @param filter.tags A list of tags that the log data should match.
* @param filter.maxLevel The maximum log level.
* @param filter.messageRegex A regex that the log level should match.
* @param filter.func A function that determines if handler is called
* @returns The handler function that was added.
*/
export declare function addHandler(handler?: LogHandler): void;
export declare function addHandler(handler: LogHandler, filter?: {
tags?: string[];
maxLevel?: LogLevel;
messageRegex?: RegExp;
func?: (logData: LogData) => boolean;
}): LogHandler;
/**
* Remove a handler.
*
* Due to how handlers are wrapped
*
* @param handler Handler to remove
* @param handler The handler function to remove.
*/
export declare function removeHandler(handler?: LogHandler): void;
export declare function removeHandler(handler: LogHandler): void;
/**

@@ -63,8 +72,8 @@ * Remove all handlers.

* @param data The log data to handle
* @param level The maximum log level to print. Defaults to `info`
* @param throttle.signature The log event signature to use for throttling. Defaults to '' (i.e. all events)
* @param throttle.duration The duration for throttling (milliseconds). Defaults to 1000ms
* @param options.maxLevel The maximum log level to print. Defaults to `info`
* @param options.throttle.signature The log event signature to use for throttling. Defaults to '' (i.e. all events)
* @param options.throttle.duration The duration for throttling (milliseconds). Defaults to 1000ms
*/
export declare function defaultHandler(data: LogData, options?: {
level?: LogLevel;
maxLevel?: LogLevel;
throttle?: {

@@ -71,0 +80,0 @@ signature?: string;

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

bus = {
/* eslint-disable @typescript-eslint/unbound-method */
emit: process.emit,

@@ -22,2 +23,3 @@ listeners: process.listeners,

removeAllListeners: process.removeAllListeners
/* eslint-enable @typescript-eslint/unbound-method */
};

@@ -108,6 +110,31 @@ }

*
* @param handler A function that handles the log data
* @param handler A function that handles the log data.
* @param filter Options for filtering log data prior to sending to the handler.
* @param filter.tags A list of tags that the log data should match.
* @param filter.maxLevel The maximum log level.
* @param filter.messageRegex A regex that the log level should match.
* @param filter.func A function that determines if handler is called
* @returns The handler function that was added.
*/
function addHandler(handler) {
bus.addListener(LOG_EVENT_NAME, handler !== undefined ? handler : defaultHandler);
function addHandler(handler, filter = {}) {
let listener = handler;
const { tags, maxLevel, messageRegex, func } = filter;
if (tags !== undefined ||
maxLevel !== undefined ||
messageRegex !== undefined ||
func !== undefined) {
listener = (logData) => {
if (tags !== undefined && !tags.includes(logData.tag))
return;
if (maxLevel !== undefined && logData.level > maxLevel)
return;
if (messageRegex !== undefined && !messageRegex.test(logData.message))
return;
if (func !== undefined && !func(logData))
return;
handler(logData);
};
}
bus.addListener(LOG_EVENT_NAME, listener);
return listener;
}

@@ -118,8 +145,6 @@ exports.addHandler = addHandler;

*
* Due to how handlers are wrapped
*
* @param handler Handler to remove
* @param handler The handler function to remove.
*/
function removeHandler(handler) {
bus.removeListener(LOG_EVENT_NAME, handler !== undefined ? handler : defaultHandler);
bus.removeListener(LOG_EVENT_NAME, handler);
}

@@ -156,5 +181,5 @@ exports.removeHandler = removeHandler;

* @param data The log data to handle
* @param level The maximum log level to print. Defaults to `info`
* @param throttle.signature The log event signature to use for throttling. Defaults to '' (i.e. all events)
* @param throttle.duration The duration for throttling (milliseconds). Defaults to 1000ms
* @param options.maxLevel The maximum log level to print. Defaults to `info`
* @param options.throttle.signature The log event signature to use for throttling. Defaults to '' (i.e. all events)
* @param options.throttle.duration The duration for throttling (milliseconds). Defaults to 1000ms
*/

@@ -164,4 +189,4 @@ function defaultHandler(data, options) {

// Skip if greater than desired reporting level
const maxLevel = options !== undefined && options.level !== undefined
? options.level
const maxLevel = options !== undefined && options.maxLevel !== undefined
? options.maxLevel
: LogLevel.info;

@@ -168,0 +193,0 @@ if (level > maxLevel)

{
"name": "@stencila/logga",
"version": "1.4.1",
"version": "2.0.0",
"description": "Unified logging across related Javascript modules",

@@ -36,8 +36,8 @@ "main": "dist/lib/index.js",

"devDependencies": {
"@stencila/dev-config": "1.1.3",
"@types/jest": "24.0.18",
"@stencila/dev-config": "1.2.2",
"@types/jest": "24.0.23",
"jest": "24.9.0",
"parcel": "^1.12.4",
"ts-jest": "24.0.2",
"typescript": "3.6.2"
"parcel": "1.12.4",
"ts-jest": "24.1.0",
"typescript": "3.7.2"
},

@@ -44,0 +44,0 @@ "jest": {

Sorry, the diff of this file is not supported yet

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