logpipes
Version:
Console.log transformation pipes
2 lines • 9.26 kB
JavaScript
(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{LOG_LEVELS:()=>r,createDateTimePipe:()=>y,createJsonPipe:()=>O,createJsonStringifyPipe:()=>L,createLogCachePipe:()=>V,createLogLevelFilterPipe:()=>M,createLogMessageFilterPipe:()=>N,createNoopPipe:()=>z,estimateArgsSizeByStringify:()=>C,generateUuidSimple:()=>P,getConsoleOverrides:()=>f,getDefaultDateTimePipeOptions:()=>p,getDefaultJsonPipeOptions:()=>x,getDefaultJsonSimplifierOptions:()=>d,getDefaultJsonStringifyPipeOptions:()=>S,getDefaultLogCachePipeOptions:()=>j,getLogMessageFilterPipeOptions:()=>I,getOriginalConsoleMethods:()=>g,installConsoleOverride:()=>s,installConsoleOverrides:()=>a,simplifyJson:()=>h,simplifyValue:()=>v,uninstallAllConsoleOverrides:()=>u,uninstallConsoleOverride:()=>l,uninstallConsoleOverrides:()=>c});const r=["debug","error","info","log","trace","warn"],n=[],o=()=>{},i={debug:o,error:o,info:o,log:o,trace:o,warn:o};function s(e){a(...Array.isArray(e)?e:[e])}function a(...e){!function(){if(i.debug===o)for(const e of r)i[e]=console[e],console[e]=(...t)=>{var r,o,s;let a=e,l=t;for(const e of n){const t=e(a,...l);if(!t||(Array.isArray(t)?0===(null!==(r=null==t?void 0:t.length)&&void 0!==r?r:0):0===(null!==(s=null===(o=t.args)||void 0===o?void 0:o.length)&&void 0!==s?s:0)))return;Array.isArray(t)?l=t:(a=t.level,l=t.args)}i[a](...l)}}();for(const t of e)!n.includes(t)&&t.onInstall&&t.onInstall(),n.push(t)}function l(e){c(...Array.isArray(e)?e:[e])}function c(...e){for(const t of e)for(let e=n.indexOf(t);e>=0;e=n.indexOf(t)){const t=n.splice(e,1)[0];!n.includes(t)&&t.onUninstall&&t.onUninstall()}!function(){if(!(n.length>0)&&i.debug!==o)for(const e of r)console[e]=i[e],i[e]=o}()}function u(){for(const e of[...n])l(e)}function f(){return[...n]}function g(){if(i.debug!==o)return Object.assign({},i);const e={};for(const t of r)e[t]=console[t];return e}function p(){return{dateFormatter:e=>new Date(e).toISOString()}}function y({dateFormatter:e}=p()){return(t,...r)=>[e(Date.now()),...r]}function d(){return{maxDepthLimit:10,maxArrayLength:100,maxObjectPropertyCount:100,isIgnoredProperty:()=>!1,replacePropertyValue:(e,t)=>t,depthLimitValue:"[Depth limit ~]",arrayLengthLimitValue:"[Array, length: $length ~]",objectPropertyCountLimitValue:"[Object, properties: $count ~]",circularReferenceValue:"[Circular ~]",functionValue:"[Function ~]",symbolValue:"[Symbol ~]"}}const m={maxDepthLimit:10,maxArrayLength:100,maxObjectPropertyCount:100,isIgnoredProperty:()=>!1,replacePropertyValue:(e,t)=>t,depthLimitValue:"[Depth limit ~]",arrayLengthLimitValue:"[Array, length: $length ~]",objectPropertyCountLimitValue:"[Object, properties: $count ~]",circularReferenceValue:"[Circular ~]",functionValue:"[Function ~]",symbolValue:"[Symbol ~]"},b=["cause","message","name","stack"];function h(e,t={},r=0,n=new Set){const o=Object.assign(Object.assign({},m),t);if(r>o.maxDepthLimit)return o.depthLimitValue;if("string"==typeof(e=v(e))||"boolean"==typeof e||"number"==typeof e||null==e)return e;if(n.has(e))return o.circularReferenceValue;if(n.add(e),Array.isArray(e))return e.length>o.maxArrayLength?o.arrayLengthLimitValue.replace("$length",`${e.length}`):e.map((e=>h(e,o,r+1,n)));const i=Object.entries(e);if(i.length>o.maxObjectPropertyCount)return o.objectPropertyCountLimitValue.replace("$count",`${i.length}`);const s={};for(const[e,t]of i)0===r&&o.isIgnoredProperty(e)||(s[e]=h(t,o,r+1,n));for(const t of b)if(!s[t]&&!o.isIgnoredProperty(t)){const i=e[t];void 0!==i&&(s[t]=h(i,o,r+1,n))}if(o.replacePropertyValue!==m.replacePropertyValue)for(const[e,t]of Object.entries(s))s[e]=o.replacePropertyValue(e,t);return s}function v(e,t={}){if(null==e)return e;switch(typeof e){case"undefined":case"boolean":case"string":return e;case"bigint":return`BigInt(${e.toString()})`;case"number":return isNaN(e)?"NaN":e===1/0?"Infinity":e===-1/0?"-Infinity":e;case"function":return t.functionValue||m.functionValue;case"symbol":return t.symbolValue||m.symbolValue;case"object":if(e instanceof Set)return[...e.keys()];if(e instanceof Map)return Object.fromEntries([...e.entries()]);if(e instanceof String||e instanceof Number||e instanceof Boolean)return e.valueOf();if(e instanceof Date)return e.toISOString()}return e}function x(){return Object.assign(Object.assign({},{maxDepthLimit:10,maxArrayLength:100,maxObjectPropertyCount:100,isIgnoredProperty:()=>!1,replacePropertyValue:(e,t)=>t,depthLimitValue:"[Depth limit ~]",arrayLengthLimitValue:"[Array, length: $length ~]",objectPropertyCountLimitValue:"[Object, properties: $count ~]",circularReferenceValue:"[Circular ~]",functionValue:"[Function ~]",symbolValue:"[Symbol ~]"}),{messagePropertyName:"message",levelPropertyName:"level",levelPropertyFormatter:e=>e,timestampPropertyName:"timestamp",timestampPropertyFormatter:e=>new Date(e).toISOString(),messageIdPropertyName:"message_id",messageIdPropertyProvider:P,isIgnoredProperty:()=>!1,getObjectMessageToken:e=>`$${e+1}`,pickFieldNameAsObjectMessageTokenForSingleFieldObjects:!1,undefinedMessageValue:void 0})}function O(e={}){const t=x(),r=Object.assign(Object.assign({},t),e);let n,o="";const i=(e,...i)=>{const s={};let a;s[r.messagePropertyName]=void 0;let l=0;for(let e=0;e<i.length;e++){const t=v(i[e]);let n=t;if("object"==typeof t&&null!==t){let o=h(t,r);if(r.pickFieldNameAsObjectMessageTokenForSingleFieldObjects&&"object"==typeof o&&null!==o){const e=Object.entries(o);if(1===e.length){const[t,r]=e[0],i=`$${t}`;if(void 0===s[i])if(n=i,null===(c=r)||"string"==typeof c||void 0===c||"number"==typeof c||"boolean"==typeof c){const e="string"==typeof r?"'":"";n+=`:[${e}${r}${e}]`,o=void 0}else o=r}}"string"!=typeof n&&(n=r.getObjectMessageToken(l,t,e),l++),s[n]=o}else void 0===t?void 0!==r.undefinedMessageValue&&(n+=r.undefinedMessageValue):n=t;a=void 0===a?`${n}`:`${a} ${n}`}var c;if(a&&(s[r.messagePropertyName]=a),r.levelPropertyName&&(s[r.levelPropertyName]=r.levelPropertyFormatter(e)),r.timestampPropertyName&&(s[r.timestampPropertyName]=r.timestampPropertyFormatter(Date.now())),r.messageIdPropertyName){let a=n||r.messageIdPropertyProvider(e,...i);void 0===a&&(a=t.messageIdPropertyProvider()),o=a,s[r.messageIdPropertyName]=o,n=void 0}return[s]};return i.getLastMessageId=()=>o,i.setNextMessageId=e=>{n=e},i}function P(){let e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const r=(e+Math.floor(16*Math.random()))%16;return e=Math.floor(e/16),("x"===t?r:3&r|8).toString(16)}))}function S(){return Object.assign(Object.assign({},x()),{preStringifyCallback:()=>{}})}function L(e={}){const t=Object.assign(Object.assign({},S()),e),r=O(t),n=(e,...n)=>{const o=r(e,...n);if(0===o.length)return[];const i=o[0];return t.preStringifyCallback(i),[JSON.stringify(i)]};return n.getLastMessageId=r.getLastMessageId,n.setNextMessageId=r.setNextMessageId,n}function j(){return{cacheSize:1e3,cacheSizeByStringify:-1}}function V(e={}){const t=Object.assign(Object.assign({},{cacheSize:1e3,cacheSizeByStringify:-1}),e);if(t.cacheSize<0||isNaN(t.cacheSize))throw new Error(`Invalid cache size: ${t.cacheSize}`);const r={size:0};let n=!1,o=0;function i(){r.first&&(o>0&&(o-=C(...r.first.value.args)),r.first=r.first.next,r.size--)}const s=(e,...a)=>{if(0===t.cacheSize||n)return a;var l;l={value:{level:e,args:a,timestamp:Date.now()}},void 0===r.last?r.first=l:r.last.next=l,r.last=l,r.size++,t.cacheSizeByStringify>=0&&(o+=C(...l.value.args));const c=r.size>t.cacheSize,u=t.cacheSizeByStringify>=0&&o>t.cacheSizeByStringify;if((c||u)&&t.onCacheSizeReached){n=!0;try{t.onCacheSizeReached(s)}finally{n=!1}}if(u){for(;o>t.cacheSizeByStringify&&void 0!==r.first;)i();o=Math.max(o,0),void 0===r.first&&(o=0)}else c&&i();return a};return s.getMessages=()=>{const e=[];let t=r.first;for(;void 0!==t;)e.push(t.value),t=t.next;return e},s.clearMessages=()=>{r.first=void 0,r.last=void 0,r.size=0,o=0},s.onInstall=()=>s.clearMessages(),s}function C(...e){let t=0;for(const r of e)void 0!==r&&(t+=JSON.stringify(h(r)).length);return t}function M(e={}){const t=Object.assign({excludedLogLevels:[]},e);return(e,...r)=>{const n="function"==typeof t.excludedLogLevels?t.excludedLogLevels(e):t.excludedLogLevels;return("boolean"==typeof n?n:n.includes(e))?[]:r}}function I(){return{isCaseSensitive:!1,excludedMessageTokens:[]}}function N(e){const{excludedMessageTokens:t,isCaseSensitive:r}=Object.assign(Object.assign({},{isCaseSensitive:!1,excludedMessageTokens:[]}),e),n=t.filter((e=>"string"==typeof e)).map((e=>r?e:e.toLowerCase())),o=t.filter((e=>"object"==typeof e));return t.sort(((e,t)=>typeof e==typeof t?0:"string"==typeof e?-1:1)),(e,...i)=>{if(0===t.length)return i;if(r){for(const e of i)if("string"==typeof e){if(n.some((t=>e.includes(t))))return[];if(o.some((t=>t.test(e))))return[]}}else for(const e of i)if("string"==typeof e){const t=e.toLowerCase();if(n.some((e=>t.includes(e))))return[];if(o.some((t=>t.test(e))))return[]}return i}}function z(){return(e,...t)=>t}module.exports=t})();
//# sourceMappingURL=index.cjs.js.map