@decaf-ts/logging
Advanced tools
+1
-1
@@ -1,2 +0,2 @@ | ||
| var e,t;e=this,t=function(e,t,r,n){"use strict";const o="ENV",s="__",i=["${","}"];var a;e.LogLevel=void 0,(a=e.LogLevel||(e.LogLevel={})).benchmark="benchmark",a.error="error",a.warn="warn",a.info="info",a.verbose="verbose",a.debug="debug",a.trace="trace",a.silly="silly";const c={benchmark:0,error:3,warn:6,info:9,verbose:12,debug:15,trace:18,silly:21};var l;e.LoggingMode=void 0,(l=e.LoggingMode||(e.LoggingMode={})).RAW="raw",l.JSON="json";const u={app:{},separator:{},class:{fg:34},id:{fg:36},stack:{},timestamp:{},message:{error:{fg:31}},method:{},logLevel:{benchmark:{fg:32,style:["bold"]},error:{fg:31,style:["bold"]},info:{fg:34,style:["bold"]},verbose:{fg:34,style:["bold"]},debug:{fg:33,style:["bold"]},trace:{fg:33,style:["bold"]},silly:{fg:33,style:["bold"]}}},g={env:"development",verbose:0,level:e.LogLevel.info,logLevel:!0,style:!1,filters:[],contextSeparator:".",separator:"-",timestamp:!0,timestampFormat:"HH:mm:ss.SSS",context:!0,meta:!0,format:e.LoggingMode.RAW,pattern:"{level} [{timestamp}] {app} {context} {separator} {message} {stack}",theme:u};class f{constructor(){this.descriptors=new Map}register(e){return this.descriptors.set(e.key,e),this}unregister(e){return this.descriptors.delete(e),this}get(e){return this.descriptors.get(e)}render(e,t){const r={},n=new Set;return t.forEach(t=>{if(n.has(t))return;n.add(t);const o=this.descriptors.get(t);if(!o)return;if(o.shouldInclude&&!o.shouldInclude(e))return;const s=o.render(e);if(void 0===s)return;const i=o.style?o.style(s,e):s;r[t]=i}),r}keys(){return Array.from(this.descriptors.keys())}}const p=new Map;function h(e){if(p.has(e))return p.get(e);const t=d(e||""),r=new Set,n=[];m(t,r,n);const o={pattern:e,segments:t,keys:n,includesMeta:r.has("meta")};return p.set(e,o),o}function y(e,t){return v(e.segments,t).text}function d(e){const t=[];let r=0;for(;r<e.length;){const n=e[r];if("["===n){const n=b(e,r,"[","]");if(-1===n){t.push({type:"literal",value:"["}),r++;continue}const o=e.slice(r+1,n);t.push({type:"optional",prefix:"[",suffix:"]",children:d(o)}),r=n+1;continue}if("{"===n){const n=e.indexOf("}",r+1);if(-1===n){t.push({type:"literal",value:"{"}),r++;continue}const o=e.slice(r+1,n).trim();t.push({type:"parameter",key:o}),r=n+1;continue}let o=r;for(;o<e.length&&"["!==e[o]&&"{"!==e[o];)o++;const s=e.slice(r,o);s.length&&t.push({type:"literal",value:s}),r=o}return t}function b(e,t,r,n){let o=0;for(let s=t;s<e.length;s++){const t=e[s];if(t===r)o++;else if(t===n&&(o--,0===o))return s}return-1}function m(e,t,r){for(const n of e)"parameter"===n.type&&(t.has(n.key)||(t.add(n.key),r.push(n.key))),"optional"===n.type&&m(n.children,t,r)}function v(e,t){const r=[];let n=!1;for(const o of e){const e=x(o,t);e.text.length&&r.push(e.text),n=n||e.hasValue}return{text:r.join(""),hasValue:n}}function x(e,t){if("literal"===e.type)return{text:e.value,hasValue:!1};if("parameter"===e.type){const r=t[e.key]??"";return{text:r,hasValue:r.length>0}}const r=v(e.children,t);return r.hasValue?{text:`${e.prefix}${r.text}${e.suffix}`,hasValue:!0}:{text:"",hasValue:!1}}const w=new f;w.register({key:"level",render(e){if(!1!==e.config.logLevel)return e.level.toUpperCase()},style:(e,t)=>t.applyTheme(e,"logLevel")}).register({key:"timestamp",shouldInclude:e=>!(!e.config.timestamp||!e.timestamp),render:e=>e.timestamp,style:(e,t)=>t.applyTheme(e,"timestamp")}).register({key:"app",shouldInclude:e=>!!e.app,render:e=>e.app,style:(e,t)=>t.applyTheme(e,"app")}).register({key:"context",shouldInclude:e=>!1!==e.config.context&&e.context.length>0,render(e){const t=e.config.contextSeparator||".";return e.context.join(t)},style:(e,t)=>t.applyTheme(e,"class")}).register({key:"separator",shouldInclude:e=>!!e.separator,render:e=>e.separator,style:(e,t)=>t.applyTheme(e,"separator")}).register({key:"message",render:e=>e.filteredMessage,style:(e,t)=>t.applyTheme(e,"message")}).register({key:"stack",shouldInclude:e=>!!e.stack,render:e=>e.stack,style:(e,t)=>t.applyTheme(e,"stack")}).register({key:"meta",shouldInclude:e=>!!e.metaString,render:e=>e.metaString}).register({key:"correlationId",shouldInclude:e=>!!e.correlationId,render:e=>e.correlationId,style:(e,t)=>t.applyTheme(e,"id")});const L=w;function E(e,t,r="g"){return Object.entries(t).forEach(([t,n])=>{const o=RegExp(k(t),r);e=e.replace(o,n)}),e}function O(e){return _(e).toUpperCase()}function _(e){return e.replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/[\s-]+/g,"_").toLowerCase()}function k(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function j(e,...t){if(t.length>1&&!t.every(e=>"string"==typeof e||"number"==typeof e))throw Error("Only string and number arguments are supported for multiple replacements.");if(1===t.length&&"object"==typeof t[0]){const r=t[0];return Object.entries(r).reduce((e,[t,r])=>e.replace(RegExp(`\\{${t}\\}`,"g"),()=>r),e)}return e.replace(/{(\d+)}/g,(e,r)=>void 0!==t[r]?t[r].toString():"undefined")}const A=j;function M(){return Object.getPrototypeOf(Object.getPrototypeOf(globalThis))!==Object.prototype}const P=Symbol("EnvironmentEmpty"),S=Symbol("EnvironmentModel"),R=/^[a-z][a-zA-Z0-9]*$/;class C extends r.ObjectAccumulator{static{this.factory=()=>new C}constructor(){super(),Object.defineProperty(this,S,{value:{},writable:!0,enumerable:!1,configurable:!1})}fromEnv(e){let t;return M()?t=globalThis[o]||{}:(t=globalThis.process.env,e=O(e)),this.parseEnvValue(t[e])}parseEnvValue(e){return C.parseRuntimeValue(e)}static parseRuntimeValue(e){if("string"!=typeof e)return e;if("true"===e)return!0;if("false"===e)return!1;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Number(t):e}expand(e){Object.entries(e).forEach(([e,t])=>{C.mergeModel(this[S],e,t),Object.defineProperty(this,e,{get:()=>{const r=this.fromEnv(e);return void 0!==r?r:t&&"object"==typeof t?Array.isArray(t)?t:C.buildEnvProxy(t,[e]):""===t?P:t},set:e=>{t=e},configurable:!0,enumerable:!0})})}orThrow(){const e=this[S],t=e=>void 0!==e?this.parseEnvValue(e):void 0,r=(e,t=!1)=>C.missingEnvError(e,t),n=(e,o)=>{const s={get(s,i){if("string"!=typeof i)return;if(Array.isArray(e)&&"length"===i)return e.length;const a=[...o,i],{key:c,value:l}=C.readRuntimeForPath(a);if("string"==typeof l&&0===l.length)throw r(c,!0);const u=t(l);if(void 0!==u){if("string"==typeof u&&0===u.length)throw r(c,!0);return u}if(!e||!Object.prototype.hasOwnProperty.call(e,i))throw r(c);const g=e[i];if(void 0!==g){if(""===g)throw r(c);return g&&"object"==typeof g?n(g,a):g}},ownKeys:()=>e?Reflect.ownKeys(e):[],getOwnPropertyDescriptor(t,r){if(e)return Object.prototype.hasOwnProperty.call(e,r)?{enumerable:!0,configurable:!0}:void 0}};return new Proxy(Array.isArray(e)?[]:{},s)};return new Proxy(this,{get(o,s,i){if("string"!=typeof s)return Reflect.get(o,s,i);if(!Object.prototype.hasOwnProperty.call(e,s))return Reflect.get(o,s,i);const{key:a,value:c}=C.readRuntimeForPath([s]);if("string"==typeof c&&0===c.length)throw r(a,!0);const l=t(c);if(void 0!==l){if("string"==typeof l&&0===l.length)throw r(a,!0);return l}const u=e[s];if(u&&"object"==typeof u)return n(u,[s]);if(void 0===u)return Reflect.get(o,s,i);const g=Reflect.get(o,s);if(void 0===g||""===g)throw r(a,""===g);return g}})}static instance(...e){if(!C._instance){const t=C.factory(...e),r=new Proxy(t,{get(e,t,r){const n=Reflect.get(e,t,r);if(n!==P&&("string"!=typeof t||!Object.prototype.hasOwnProperty.call(e,t)||void 0!==n)){if(void 0!==n)return n;if("string"==typeof t){if("app"===t)return;return C.buildEnvProxy(void 0,[t])}return n}}});C._instance=r}return C._instance}accumulate(e){return super.accumulate(e),this}static accumulate(e){const t=C.instance();return Object.keys(t).forEach(e=>{const r=Object.getOwnPropertyDescriptor(t,e);r&&r.configurable&&r.enumerable&&Object.defineProperty(t,e,{...r,enumerable:!1})}),t.accumulate(e),t}static get(e){return C._instance.get(e)}static formatEnvSegment(e){return R.test(e)?O(e):e.toUpperCase()}static buildEnvKey(e){return e.map(e=>C.formatEnvSegment(e)).join(s)}static buildRawKey(e){return e.join(s)}static readRuntimeForPath(e){const t=C.buildEnvKey(e),r=C.buildRawKey(e),n=C.readRuntimeEnv(t);if(void 0!==n)return{key:t,value:n};if(r!==t){const e=C.readRuntimeEnv(r);if(void 0!==e)return{key:r,value:e}}return{key:t,value:void 0}}static buildEnvProxy(e,t){const r=e=>C.readRuntimeEnv(e),n=/^[0-9]+$/,o={get(o,s){if(s===Symbol.toPrimitive)return()=>C.buildEnvKey(t);if("toString"===s)return()=>C.buildEnvKey(t);if("valueOf"===s)return()=>C.buildEnvKey(t);if("symbol"==typeof s)return;if(Array.isArray(e)&&"length"===s)return e.length;const i=[...t,s],a=C.buildEnvKey(i),c=C.buildRawKey(i);let l=r(a);if(void 0===l&&c!==a&&(l=r(c)),void 0!==l)return C.parseRuntimeValue(l);const u=!!e&&Object.prototype.hasOwnProperty.call(e,s),g=u?e[s]:void 0;if(Array.isArray(e)&&(e=>"string"==typeof e&&n.test(e))(s)){if(!u)return;return g&&"object"==typeof g?C.buildEnvProxy(g,i):C.parseRuntimeValue(g)}return g&&"object"==typeof g?C.buildEnvProxy(g,i):u&&""===g||u&&void 0===g?void 0:u?C.parseRuntimeValue(g):C.buildEnvProxy(void 0,i)},ownKeys:()=>e?Reflect.ownKeys(e):[],getOwnPropertyDescriptor(t,r){if(e)return Object.prototype.hasOwnProperty.call(e,r)?{enumerable:!0,configurable:!0}:void 0}};return new Proxy(Array.isArray(e)?[]:{},o)}static keys(e=!0){return C.instance().keys().map(t=>e?O(t):t)}static mergeModel(e,t,r){if(e){if(r&&"object"==typeof r&&!Array.isArray(r)){const n=e[t],o=n&&"object"==typeof n&&!Array.isArray(n)?n:{};return e[t]=o,void Object.entries(r).forEach(([e,t])=>{C.mergeModel(o,e,t)})}e[t]=r}}static readRuntimeEnv(e){if(M()){const t=globalThis[o];return t?t[e]:void 0}return globalThis?.process?.env?.[e]}static missingEnvError(e,t){return Error(`Environment variable ${e} is required but was ${t?"an empty string":"undefined"}.`)}}const $=C.accumulate(Object.assign({app:void 0},g,{env:(M()&&globalThis[o]?globalThis[o].NODE_ENV:globalThis.process.env.NODE_ENV)||"development"}));function T(e){if("function"!=typeof e)return!1;try{const t=Function.prototype.toString.call(e);if(/^\s*class[\s{]/.test(t))return!0}catch{}const t=Object.getOwnPropertyDescriptor(e,"prototype");if(!t||!t.value)return!1;if(!1===t.writable)return!0;const r=e.prototype;return!!Object.prototype.hasOwnProperty.call(r,"constructor")&&Object.getOwnPropertyNames(r).filter(e=>"constructor"!==e).length>0}function I(e){return"function"==typeof e&&!T(e)}function V(e){if(!I(e))return!1;const t=Object.getOwnPropertyDescriptor(e,"prototype");return!t||void 0===t.value}function N(e){if(null===e||"object"!=typeof e)return!1;const t=e.constructor;return!(!t||t===Object)&&T(t)}function F(e){if(null===e)return"null";if(void 0===e)return"undefined";if("string"==typeof e)return e;if(T(e))return e.name||"AnonymousClass";if(N(e)){const t=e.toString;if("function"==typeof t&&t!==Object.prototype.toString)try{const r=t.call(e);if("string"==typeof r&&r.length)return r}catch{}const r=e.constructor;return r&&r.name?r.name:"AnonymousInstance"}if(V(e)||I(e)){const t=e;return t.name?t.name:"anonymous"}if("object"==typeof e){const t=Object.prototype.toString.call(e),r=/^\[object ([^\]]+)\]$/.exec(t);return r?.[1]?r[1]:"Object"}return typeof e}const K=Symbol("MiniLoggerRootContext");class D{constructor(e,t,r=[]){this.conf=t,this.baseContext=Array.isArray(r)?[...r]:[],e&&this.baseContext.push(e),this.context=[...this.baseContext],this[K]=[...this.baseContext]}config(e){return this.conf&&e in this.conf?this.conf[e]:z.getConfig()[e]}for(e,t,...r){let n,o=t;const s=Array.isArray(this.context)?[...this.context]:"string"==typeof this.context&&this.context?[this.context]:[],i=this[K],a=Array.isArray(i)?[...i]:Array.isArray(this.baseContext)?[...this.baseContext]:[];"string"==typeof e?n=e:void 0!==e&&(T(e)||N(e)||I(e)?n=F(e):!o&&e&&"object"==typeof e&&(o=e));let c=n?[...s,n]:[...s];return new Proxy(this,{get:(e,t,r)=>{const n=Reflect.get(e,t,r);return"config"===t?new Proxy(this.config,{apply:(e,t,n)=>{const[s]=n;return o&&void 0!==s&&s in o?o[s]:Reflect.apply(e,r,n)},get:(e,t)=>o&&t in o?o[t]:Reflect.get(e,t,r)}):"clear"===t?()=>(c=[...a],o=void 0,r):"context"===t?c:"root"===t?[...a]:t===K?a:"for"===t?(...t)=>{const r=Array.isArray(e.context)?[...e.context]:"string"==typeof e.context&&e.context?[e.context]:[];e.context=[...c];try{return e.for.apply(e,t)}finally{e.context=r}}:n}})}getConfigSnapshot(){return{...z.getConfig(),...this.conf||{}}}getContextSegments(){return Array.isArray(this.context)?[...this.context]:"string"==typeof this.context&&this.context?[this.context]:[]}resolveFilters(e){const t=e.filters||[];return Array.isArray(t)?t.filter(e=>"object"==typeof e&&null!==e&&"function"==typeof e.filter):[]}applyFilters(e,t,r){const n=this.resolveFilters(r);return n.length?n.reduce((e,n)=>{try{const o=n.filter(r,e,[...t]);return"string"==typeof o?o:e}catch{return e}},e):e}createLog(e,t,r,n){const o=!!this.config("style"),s=this.config("separator"),i=z.getConfig().app,a=this.config("timestamp")?(new Date).toISOString():void 0,c=this.getConfigSnapshot(),l=this.getContextSegments(),u="string"==typeof t?t:t instanceof Error?t.message:t+"",g=this.applyFilters(u,l,c),f=this.config("meta")&&n?n:void 0,p=f?this.formatMeta(f):void 0,d=p?this.applyFilters(p,l,c):void 0,b=this.config("correlationId"),m=null!=b?b+"":void 0;let v,x;if(r||t instanceof Error){const n=r||t;n.stack&&(x="string"==typeof t?g:n.message,v=` | ${x} - Stack trace:\n${o?z.theme(n.stack,"stack",e):n.stack}`)}const w={config:c,level:e,context:l,timestamp:a,app:"string"==typeof i&&i.length?i:void 0,separator:s,correlationId:m,rawMessage:u,filteredMessage:g,meta:f,metaString:d,stack:v,stackLabel:x,applyTheme:(t,r)=>o?z.theme(t,r,e):t},E=this.config("pattern"),O=c.pattern||"",_=h(E.length?E:O),k=L.render(w,_.keys);switch(this.config("format")){case"json":{const e=L.render(w,L.keys()),t={};return Object.entries(e).forEach(([e,r])=>{"meta"!==e&&(t[e]=r)}),w.meta&&(t.meta=w.meta),JSON.stringify(t)}case"raw":{let e=this.normalizePatternSpacing(y(_,k));return!_.includesMeta&&d&&(e=e?`${e} ${d}`:d),e}default:throw Error("Unsupported logging format: "+this.config("format"))}}formatMeta(e){try{return JSON.stringify(e)}catch(t){return e+""}}normalizePatternSpacing(e){return e.replace(/[ \t]{2,}/g," ").replace(/^[ \t]+|[ \t]+$/g,"")}log(t,r,n,o){const s=this.config("level");if(c[t]>c[s])return;let i;switch(t){case e.LogLevel.benchmark:case e.LogLevel.info:case e.LogLevel.verbose:i=console.log;break;case e.LogLevel.debug:i=console.debug;break;case e.LogLevel.error:i=console.error;break;case e.LogLevel.trace:i=console.trace;break;case e.LogLevel.warn:i=console.warn;break;case e.LogLevel.silly:i=console.debug;break;default:throw Error("Invalid log level")}i(this.createLog(t,r,n,o))}benchmark(t,r){this.log(e.LogLevel.benchmark,t,void 0,r)}silly(t,r=0,n){const o="number"==typeof r?r:0,s="number"==typeof r?n:r;this.config("verbose")<o||this.log(e.LogLevel.silly,t,void 0,s)}verbose(t,r=0,n){const o="number"==typeof r?r:0,s="number"==typeof r?n:r;this.config("verbose")<o||this.log(e.LogLevel.verbose,t,void 0,s)}info(t,r){this.log(e.LogLevel.info,t,void 0,r)}debug(t,r){this.log(e.LogLevel.debug,t,void 0,r)}error(t,r,n){let o,s;r instanceof Error?(o=r,s=n):s=r,this.log(e.LogLevel.error,t,o,s)}warn(t,r){this.log(e.LogLevel.warn,t,void 0,r)}trace(t,r){this.log(e.LogLevel.trace,t,void 0,r)}setConfig(e){this.conf={...this.conf||{},...e}}get root(){return[...this.baseContext]}clear(){return this.context=[...this.baseContext],this}}class z{static{this._factory=(e,t)=>{const r="string"==typeof $.app?[$.app]:[];return new D(e,t,r)}}static{this._config=$}constructor(){}static setFactory(e){z._factory=e,this.global=void 0}static setConfig(e){Object.entries(e).forEach(([e,t])=>{this._config[e]=t})}static getConfig(){return this._config}static get(){return this.ensureRoot()}static verbose(e,t=0,r){return this.get().verbose(e,t,r)}static info(e,t){return this.get().info(e,t)}static trace(e,t){return this.get().trace(e,t)}static debug(e,t){return this.get().debug(e,t)}static benchmark(e,t){return this.get().benchmark(e,t)}static silly(e,t=0,r){return this.get().silly(e,t,r)}static warn(e,t){return this.get().warn(e,t)}static error(e,t,r){return this.get().error(e,t,r)}static for(e,t,...r){const n=void 0!==t?[e,t]:[e];return(this.global?this.global:this.ensureRoot(r)).for(...n)}static because(e,t){let r=this.ensureRoot().for(e,this._config);return t&&(r=r.for(t)),r}static baseContext(){const e=this._config.app;return"string"==typeof e&&e.length?[e]:[]}static attachRootContext(e){const t=e.root&&Array.isArray(e.root)?[...e.root]:this.baseContext();return(!e.context||Array.isArray(e.context)&&0===e.context.length)&&(e.context=[...t]),e[K]=[...t],e}static ensureRoot(e=[]){if(!this.global){const t=this._factory(void 0,void 0,...e);this.global=this.attachRootContext(t)}return this.global}static theme(r,n,o,s=u){if(!this._config.style)return r;const i=s[n];if(!i||!Object.keys(i).length)return r;let a=i;const c=Object.assign({},e.LogLevel);return Object.keys(i)[0]in c&&(a=i[o]||{}),Object.keys(a).reduce((e,r)=>{const n=a[r];return n?((e,r,n)=>{try{const o=e;let s=t.style(o);function i(e,r=!1){let i=r?s.background:s.foreground;if(!Array.isArray(e))return i.call(s,n);switch(e.length){case 1:return i=r?s.bgColor256:s.color256,i(e[0]);case 3:return i=r?s.bgRgb:s.rgb,s.rgb(e[0],e[1],e[2]);default:return t.style(o)}}function a(e){s="number"==typeof e?s.style(e):s[e]}switch(r){case"bg":case"fg":return i(n).text;case"style":return Array.isArray(n)?n.forEach(a):a(n),s.text;default:return o}}catch(c){return e}})(e,r,n):e},r)}static register(e){return L.register(e)}static unregister(e){return L.unregister(e)}}class U{get log(){return this._log||(this._log=z.for(this)),this._log}constructor(){}}class J extends U{get log(){return super.log.for(this,{filters:[]})}}const Z="undefined"!=typeof globalThis&&"function"==typeof globalThis.performance?.now?()=>globalThis.performance.now():"undefined"!=typeof process&&"function"==typeof process.hrtime?.bigint?()=>{const e=process.hrtime.bigint();return Number(e)/1e6}:()=>Date.now();function q(e){const t=0>e?"-":"",r=Math.abs(e),n=Math.floor(r/36e5),o=Math.floor(r%36e5/6e4),s=Math.floor(r%6e4/1e3),i=Math.floor(r%1e3),a=(e,t)=>e.toString().padStart(t,"0");return`${t}${a(n,2)}:${a(o,2)}:${a(s,2)}.${a(i,3)}`}function B(t=e.LogLevel.info,r=0,n=(...e)=>"called with "+e,o){return(e,s,i)=>{if(!i||"number"==typeof i)throw Error("Logging decoration only applies to methods");const a=e instanceof U?e.log.for(e[s]):z.for(e).for(e[s]),c=a[t].bind(a),l=i.value;return i.value=new Proxy(l,{apply(e,t,s){c(n(...s),r);try{const r=Reflect.apply(e,t,s);return r instanceof Promise?r.then(e=>(o&&c(o(void 0,e)),e)).catch(e=>{throw o&&a.error(o(e)),e}):(o&&c(o(void 0,r)),r)}catch(e){throw o&&a.error(o(e)),e}}}),i}}function W(){return(e,t,r)=>{if(!r)throw Error("final decorator can only be used on methods");return r?.configurable&&(r.configurable=!1),r}}class H extends J{constructor(e,t){super(),this.regexp=e,this.replacement=t}match(e){const t=this.regexp.exec(e);return this.regexp.lastIndex=0,t}filter(e,t,r){const n=this.log.for(this.filter);if(!this.match(t))return t;try{return t.replace(this.regexp,this.replacement)}catch(e){n.error("PatternFilter replacement error: "+e)}return""}}n.__decorate([W(),n.__metadata("design:type",Function),n.__metadata("design:paramtypes",[String]),n.__metadata("design:returntype",void 0)],H.prototype,"match",null),e.BrowserEnvKey=o,e.DefaultLoggingConfig=g,e.DefaultPlaceholderWrappers=i,e.DefaultTheme=u,e.ENV_PATH_DELIMITER=s,e.Environment=C,e.LogFilter=J,e.LogParameterRegistry=f,e.LoggedClass=U,e.LoggedEnvironment=$,e.Logging=z,e.MiniLogger=D,e.NumericLogLevels=c,e.PACKAGE_NAME="@decaf-ts/logging",e.PatternFilter=H,e.ROOT_CONTEXT_SYMBOL=K,e.StopWatch=class{constructor(e=!1){this._startMs=null,this._elapsedMs=0,this._running=!1,this._laps=[],this._lastLapTotalMs=0,e&&this.start()}get running(){return this._running}get elapsedMs(){return this._running&&null!=this._startMs?this._elapsedMs+(Z()-this._startMs):this._elapsedMs}start(){return this._running||(this._running=!0,this._startMs=Z()),this}pause(){return this._running&&null!=this._startMs&&(this._elapsedMs+=Z()-this._startMs,this._startMs=null,this._running=!1),this}resume(){return this._running||(this._running=!0,this._startMs=Z()),this}stop(){return this.pause(),this._elapsedMs}reset(){const e=this._running;return this._startMs=e?Z():null,this._elapsedMs=0,this._laps=[],this._lastLapTotalMs=0,this}lap(e){const t=this.elapsedMs,r=t-this._lastLapTotalMs,n={index:this._laps.length,label:e,ms:r,totalMs:t};return this._laps.push(n),this._lastLapTotalMs=t,n}get laps(){return this._laps}toString(){return q(this.elapsedMs)}toJSON(){return{running:this._running,elapsedMs:this.elapsedMs,laps:this._laps.slice()}}},e.VERSION="0.16.0",e.benchmark=()=>(e,t,r)=>{if(!r||"number"==typeof r)throw Error("benchmark decoration only applies to methods");const n=e instanceof U?e.log.for(e[t]):z.for(e).for(e[t]),o=r.value;return r.value=new Proxy(o,{apply(e,t,r){const o=Z();try{const s=Reflect.apply(e,t,r);return s instanceof Promise?s.then(e=>(n.benchmark(`completed in ${Z()-o}ms`),e)).catch(e=>{throw n.benchmark(`failed in ${Z()-o}ms`),e}):(n.benchmark(`completed in ${Z()-o}ms`),s)}catch(e){throw n.benchmark(`failed in ${Z()-o}ms`),e}}}),r},e.compileLogPattern=h,e.debug=()=>B(e.LogLevel.debug,0,(...e)=>"called with "+e,(e,t)=>e?"Failed with: "+e:t?"Completed with "+JSON.stringify(t):"completed"),e.escapeRegExp=k,e.final=W,e.formatMs=q,e.getObjectName=F,e.info=()=>B(e.LogLevel.info),e.isBrowser=M,e.isClass=T,e.isFunction=I,e.isInstance=N,e.isMethod=V,e.log=B,e.logParameterRegistry=L,e.now=Z,e.padEnd=(e,t,r=" ")=>{if(1!==r.length)throw Error("Invalid character length for padding. must be one!");return e.padEnd(t,r)},e.patchPlaceholders=(e,t,r=i[0],n=i[1],o="g")=>E(e,Object.entries(t).reduce((e,[t,o])=>(e[`${r}${t}${n}`]=o,e),{}),o),e.patchString=E,e.renderPattern=y,e.sf=j,e.silly=()=>B(e.LogLevel.silly),e.stringFormat=A,e.toCamelCase=e=>e.replace(/(?:^\w|[A-Z]|\b\w)/g,(e,t)=>0===t?e.toLowerCase():e.toUpperCase()).replace(/\s+/g,""),e.toENVFormat=O,e.toKebabCase=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase(),e.toPascalCase=e=>e.replace(/(?:^\w|[A-Z]|\b\w)/g,e=>e.toUpperCase()).replace(/\s+/g,""),e.toSnakeCase=_,e.trace=()=>B(e.LogLevel.trace),e.verbose=(t=0)=>(t||(t=0),B(e.LogLevel.verbose,t)),Object.keys(t).forEach(r=>{"default"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:()=>t[r]})})},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("styled-string-builder"),require("typed-object-accumulator"),require("tslib")):"function"==typeof define&&define.amd?define(["exports","styled-string-builder","typed-object-accumulator","tslib"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).logging={},e.styledStringBuilder,e.typedObjectAccumulator,e.tslib); | ||
| var e,t;e=this,t=function(e,t,r,n){"use strict";const o="ENV",s="__",i=["${","}"];var a;e.LogLevel=void 0,(a=e.LogLevel||(e.LogLevel={})).benchmark="benchmark",a.error="error",a.warn="warn",a.info="info",a.verbose="verbose",a.debug="debug",a.trace="trace",a.silly="silly";const c={benchmark:0,error:3,warn:6,info:9,verbose:12,debug:15,trace:18,silly:21};var l;e.LoggingMode=void 0,(l=e.LoggingMode||(e.LoggingMode={})).RAW="raw",l.JSON="json";const u={app:{},separator:{},class:{fg:34},id:{fg:36},stack:{},timestamp:{},message:{error:{fg:31}},method:{},logLevel:{benchmark:{fg:32,style:["bold"]},error:{fg:31,style:["bold"]},info:{fg:34,style:["bold"]},verbose:{fg:34,style:["bold"]},debug:{fg:33,style:["bold"]},trace:{fg:33,style:["bold"]},silly:{fg:33,style:["bold"]}}},g={env:"development",verbose:0,level:e.LogLevel.info,logLevel:!0,style:!1,filters:[],contextSeparator:".",separator:"-",timestamp:!0,timestampFormat:"HH:mm:ss.SSS",context:!0,meta:!0,format:e.LoggingMode.RAW,pattern:"{level} [{timestamp}] {app} {context} {separator} {message} {stack}",theme:u};class f{constructor(){this.descriptors=new Map}register(e){return this.descriptors.set(e.key,e),this}unregister(e){return this.descriptors.delete(e),this}get(e){return this.descriptors.get(e)}render(e,t){const r={},n=new Set;return t.forEach(t=>{if(n.has(t))return;n.add(t);const o=this.descriptors.get(t);if(!o)return;if(o.shouldInclude&&!o.shouldInclude(e))return;const s=o.render(e);if(void 0===s)return;const i=o.style?o.style(s,e):s;r[t]=i}),r}keys(){return Array.from(this.descriptors.keys())}}const p=new Map;function h(e){if(p.has(e))return p.get(e);const t=d(e||""),r=new Set,n=[];m(t,r,n);const o={pattern:e,segments:t,keys:n,includesMeta:r.has("meta")};return p.set(e,o),o}function y(e,t){return v(e.segments,t).text}function d(e){const t=[];let r=0;for(;r<e.length;){const n=e[r];if("["===n){const n=b(e,r,"[","]");if(-1===n){t.push({type:"literal",value:"["}),r++;continue}const o=e.slice(r+1,n);t.push({type:"optional",prefix:"[",suffix:"]",children:d(o)}),r=n+1;continue}if("{"===n){const n=e.indexOf("}",r+1);if(-1===n){t.push({type:"literal",value:"{"}),r++;continue}const o=e.slice(r+1,n).trim();t.push({type:"parameter",key:o}),r=n+1;continue}let o=r;for(;o<e.length&&"["!==e[o]&&"{"!==e[o];)o++;const s=e.slice(r,o);s.length&&t.push({type:"literal",value:s}),r=o}return t}function b(e,t,r,n){let o=0;for(let s=t;s<e.length;s++){const t=e[s];if(t===r)o++;else if(t===n&&(o--,0===o))return s}return-1}function m(e,t,r){for(const n of e)"parameter"===n.type&&(t.has(n.key)||(t.add(n.key),r.push(n.key))),"optional"===n.type&&m(n.children,t,r)}function v(e,t){const r=[];let n=!1;for(const o of e){const e=x(o,t);e.text.length&&r.push(e.text),n=n||e.hasValue}return{text:r.join(""),hasValue:n}}function x(e,t){if("literal"===e.type)return{text:e.value,hasValue:!1};if("parameter"===e.type){const r=t[e.key]??"";return{text:r,hasValue:r.length>0}}const r=v(e.children,t);return r.hasValue?{text:`${e.prefix}${r.text}${e.suffix}`,hasValue:!0}:{text:"",hasValue:!1}}const w=new f;w.register({key:"level",render(e){if(!1!==e.config.logLevel)return e.level.toUpperCase()},style:(e,t)=>t.applyTheme(e,"logLevel")}).register({key:"timestamp",shouldInclude:e=>!(!e.config.timestamp||!e.timestamp),render:e=>e.timestamp,style:(e,t)=>t.applyTheme(e,"timestamp")}).register({key:"app",shouldInclude:e=>!!e.app,render:e=>e.app,style:(e,t)=>t.applyTheme(e,"app")}).register({key:"context",shouldInclude:e=>!1!==e.config.context&&e.context.length>0,render(e){const t=e.config.contextSeparator||".";return e.context.join(t)},style:(e,t)=>t.applyTheme(e,"class")}).register({key:"separator",shouldInclude:e=>!!e.separator,render:e=>e.separator,style:(e,t)=>t.applyTheme(e,"separator")}).register({key:"message",render:e=>e.filteredMessage,style:(e,t)=>t.applyTheme(e,"message")}).register({key:"stack",shouldInclude:e=>!!e.stack,render:e=>e.stack,style:(e,t)=>t.applyTheme(e,"stack")}).register({key:"meta",shouldInclude:e=>!!e.metaString,render:e=>e.metaString}).register({key:"correlationId",shouldInclude:e=>!!e.correlationId,render:e=>e.correlationId,style:(e,t)=>t.applyTheme(e,"id")});const L=w;function E(e,t,r="g"){return Object.entries(t).forEach(([t,n])=>{const o=RegExp(k(t),r);e=e.replace(o,n)}),e}function O(e){return _(e).toUpperCase()}function _(e){return e.replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/[\s-]+/g,"_").toLowerCase()}function k(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function j(e,...t){if(t.length>1&&!t.every(e=>"string"==typeof e||"number"==typeof e))throw Error("Only string and number arguments are supported for multiple replacements.");if(1===t.length&&"object"==typeof t[0]){const r=t[0];return Object.entries(r).reduce((e,[t,r])=>e.replace(RegExp(`\\{${t}\\}`,"g"),()=>r),e)}return e.replace(/{(\d+)}/g,(e,r)=>void 0!==t[r]?t[r].toString():"undefined")}const A=j;function M(){return Object.getPrototypeOf(Object.getPrototypeOf(globalThis))!==Object.prototype}const P=Symbol("EnvironmentEmpty"),S=Symbol("EnvironmentModel"),R=/^[a-z][a-zA-Z0-9]*$/;class C extends r.ObjectAccumulator{static{this.factory=()=>new C}constructor(){super(),Object.defineProperty(this,S,{value:{},writable:!0,enumerable:!1,configurable:!1})}fromEnv(e){let t;return M()?t=globalThis[o]||{}:(t=globalThis.process.env,e=O(e)),this.parseEnvValue(t[e])}parseEnvValue(e){return C.parseRuntimeValue(e)}static parseRuntimeValue(e){if("string"!=typeof e)return e;if("true"===e)return!0;if("false"===e)return!1;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Number(t):e}expand(e){Object.entries(e).forEach(([e,t])=>{C.mergeModel(this[S],e,t),Object.defineProperty(this,e,{get:()=>{const r=this.fromEnv(e);return void 0!==r?r:t&&"object"==typeof t?Array.isArray(t)?t:C.buildEnvProxy(t,[e]):""===t?P:t},set:e=>{t=e},configurable:!0,enumerable:!0})})}orThrow(){const e=this[S],t=e=>void 0!==e?this.parseEnvValue(e):void 0,r=(e,t=!1)=>C.missingEnvError(e,t),n=(e,o)=>{const s={get(s,i){if("string"!=typeof i)return;if(Array.isArray(e)&&"length"===i)return e.length;const a=[...o,i],{key:c,value:l}=C.readRuntimeForPath(a);if("string"==typeof l&&0===l.length)throw r(c,!0);const u=t(l);if(void 0!==u){if("string"==typeof u&&0===u.length)throw r(c,!0);return u}if(!e||!Object.prototype.hasOwnProperty.call(e,i))throw r(c);const g=e[i];if(void 0!==g){if(""===g)throw r(c);return g&&"object"==typeof g?n(g,a):g}},ownKeys:()=>e?Reflect.ownKeys(e):[],getOwnPropertyDescriptor(t,r){if(e)return Object.prototype.hasOwnProperty.call(e,r)?{enumerable:!0,configurable:!0}:void 0}};return new Proxy(Array.isArray(e)?[]:{},s)};return new Proxy(this,{get(o,s,i){if("string"!=typeof s)return Reflect.get(o,s,i);if(!Object.prototype.hasOwnProperty.call(e,s))return Reflect.get(o,s,i);const{key:a,value:c}=C.readRuntimeForPath([s]);if("string"==typeof c&&0===c.length)throw r(a,!0);const l=t(c);if(void 0!==l){if("string"==typeof l&&0===l.length)throw r(a,!0);return l}const u=e[s];if(u&&"object"==typeof u)return n(u,[s]);if(void 0===u)return Reflect.get(o,s,i);const g=Reflect.get(o,s);if(void 0===g||""===g)throw r(a,""===g);return g}})}static instance(...e){if(!C._instance){const t=C.factory(...e),r=new Proxy(t,{get(e,t,r){const n=Reflect.get(e,t,r);if(n!==P&&("string"!=typeof t||!Object.prototype.hasOwnProperty.call(e,t)||void 0!==n)){if(void 0!==n)return n;if("string"==typeof t){if("app"===t)return;return C.buildEnvProxy(void 0,[t])}return n}}});C._instance=r}return C._instance}accumulate(e){return super.accumulate(e),this}static accumulate(e){const t=C.instance();return Object.keys(t).forEach(e=>{const r=Object.getOwnPropertyDescriptor(t,e);r&&r.configurable&&r.enumerable&&Object.defineProperty(t,e,{...r,enumerable:!1})}),t.accumulate(e),t}static get(e){return C._instance.get(e)}static formatEnvSegment(e){return R.test(e)?O(e):e.toUpperCase()}static buildEnvKey(e){return e.map(e=>C.formatEnvSegment(e)).join(s)}static buildRawKey(e){return e.join(s)}static readRuntimeForPath(e){const t=C.buildEnvKey(e),r=C.buildRawKey(e),n=C.readRuntimeEnv(t);if(void 0!==n)return{key:t,value:n};if(r!==t){const e=C.readRuntimeEnv(r);if(void 0!==e)return{key:r,value:e}}return{key:t,value:void 0}}static buildEnvProxy(e,t){const r=e=>C.readRuntimeEnv(e),n=/^[0-9]+$/,o={get(o,s){if(s===Symbol.toPrimitive)return()=>C.buildEnvKey(t);if("toString"===s)return()=>C.buildEnvKey(t);if("valueOf"===s)return()=>C.buildEnvKey(t);if("symbol"==typeof s)return;if(Array.isArray(e)&&"length"===s)return e.length;const i=[...t,s],a=C.buildEnvKey(i),c=C.buildRawKey(i);let l=r(a);if(void 0===l&&c!==a&&(l=r(c)),void 0!==l)return C.parseRuntimeValue(l);const u=!!e&&Object.prototype.hasOwnProperty.call(e,s),g=u?e[s]:void 0;if(Array.isArray(e)&&(e=>"string"==typeof e&&n.test(e))(s)){if(!u)return;return g&&"object"==typeof g?C.buildEnvProxy(g,i):C.parseRuntimeValue(g)}return g&&"object"==typeof g?C.buildEnvProxy(g,i):u&&""===g||u&&void 0===g?void 0:u?C.parseRuntimeValue(g):C.buildEnvProxy(void 0,i)},ownKeys:()=>e?Reflect.ownKeys(e):[],getOwnPropertyDescriptor(t,r){if(e)return Object.prototype.hasOwnProperty.call(e,r)?{enumerable:!0,configurable:!0}:void 0}};return new Proxy(Array.isArray(e)?[]:{},o)}static keys(e=!0){return C.instance().keys().map(t=>e?O(t):t)}static mergeModel(e,t,r){if(e){if(r&&"object"==typeof r&&!Array.isArray(r)){const n=e[t],o=n&&"object"==typeof n&&!Array.isArray(n)?n:{};return e[t]=o,void Object.entries(r).forEach(([e,t])=>{C.mergeModel(o,e,t)})}e[t]=r}}static readRuntimeEnv(e){if(M()){const t=globalThis[o];return t?t[e]:void 0}return globalThis?.process?.env?.[e]}static missingEnvError(e,t){return Error(`Environment variable ${e} is required but was ${t?"an empty string":"undefined"}.`)}}const $=C.accumulate(Object.assign({app:void 0},g,{env:(M()&&globalThis[o]?globalThis[o].NODE_ENV:globalThis.process.env.NODE_ENV)||"development"}));function T(e){if("function"!=typeof e)return!1;try{const t=Function.prototype.toString.call(e);if(/^\s*class[\s{]/.test(t))return!0}catch{}const t=Object.getOwnPropertyDescriptor(e,"prototype");if(!t||!t.value)return!1;if(!1===t.writable)return!0;const r=e.prototype;return!!Object.prototype.hasOwnProperty.call(r,"constructor")&&Object.getOwnPropertyNames(r).filter(e=>"constructor"!==e).length>0}function I(e){return"function"==typeof e&&!T(e)}function V(e){if(!I(e))return!1;const t=Object.getOwnPropertyDescriptor(e,"prototype");return!t||void 0===t.value}function N(e){if(null===e||"object"!=typeof e)return!1;const t=e.constructor;return!(!t||t===Object)&&T(t)}function F(e){if(null===e)return"null";if(void 0===e)return"undefined";if("string"==typeof e)return e;if(T(e))return e.name||"AnonymousClass";if(N(e)){const t=e.toString;if("function"==typeof t&&t!==Object.prototype.toString)try{const r=t.call(e);if("string"==typeof r&&r.length)return r}catch{}const r=e.constructor;return r&&r.name?r.name:"AnonymousInstance"}if(V(e)||I(e)){const t=e;return t.name?t.name:"anonymous"}if("object"==typeof e){const t=Object.prototype.toString.call(e),r=/^\[object ([^\]]+)\]$/.exec(t);return r?.[1]?r[1]:"Object"}return typeof e}const K=Symbol("MiniLoggerRootContext");class D{constructor(e,t,r=[]){this.conf=t,this.baseContext=Array.isArray(r)?[...r]:[],e&&this.baseContext.push(e),this.context=[...this.baseContext],this[K]=[...this.baseContext]}config(e){return this.conf&&e in this.conf?this.conf[e]:z.getConfig()[e]}for(e,t,...r){let n,o=t;const s=Array.isArray(this.context)?[...this.context]:"string"==typeof this.context&&this.context?[this.context]:[],i=this[K],a=Array.isArray(i)?[...i]:Array.isArray(this.baseContext)?[...this.baseContext]:[];"string"==typeof e?n=e:void 0!==e&&(T(e)||N(e)||I(e)?n=F(e):!o&&e&&"object"==typeof e&&(o=e));let c=n?[...s,n]:[...s];return new Proxy(this,{get:(e,t,r)=>{const n=Reflect.get(e,t,r);return"config"===t?new Proxy(this.config,{apply:(e,t,n)=>{const[s]=n;return o&&void 0!==s&&s in o?o[s]:Reflect.apply(e,r,n)},get:(e,t)=>o&&t in o?o[t]:Reflect.get(e,t,r)}):"clear"===t?()=>(c=[...a],o=void 0,r):"context"===t?c:"root"===t?[...a]:t===K?a:"for"===t?(...t)=>{const r=Array.isArray(e.context)?[...e.context]:"string"==typeof e.context&&e.context?[e.context]:[];e.context=[...c];try{return e.for.apply(e,t)}finally{e.context=r}}:n}})}getConfigSnapshot(){return{...z.getConfig(),...this.conf||{}}}getContextSegments(){return Array.isArray(this.context)?[...this.context]:"string"==typeof this.context&&this.context?[this.context]:[]}resolveFilters(e){const t=e.filters||[];return Array.isArray(t)?t.filter(e=>"object"==typeof e&&null!==e&&"function"==typeof e.filter):[]}applyFilters(e,t,r){const n=this.resolveFilters(r);return n.length?n.reduce((e,n)=>{try{const o=n.filter(r,e,[...t]);return"string"==typeof o?o:e}catch{return e}},e):e}createLog(e,t,r,n){const o=!!this.config("style"),s=this.config("separator"),i=z.getConfig().app,a=this.config("timestamp")?(new Date).toISOString():void 0,c=this.getConfigSnapshot(),l=this.getContextSegments(),u="string"==typeof t?t:t instanceof Error?t.message:t+"",g=this.applyFilters(u,l,c),f=this.config("meta")&&n?n:void 0,p=f?this.formatMeta(f):void 0,d=p?this.applyFilters(p,l,c):void 0,b=this.config("correlationId"),m=null!=b?b+"":void 0;let v,x;if(r||t instanceof Error){const n=r||t;n.stack&&(x="string"==typeof t?g:n.message,v=` | ${x} - Stack trace:\n${o?z.theme(n.stack,"stack",e):n.stack}`)}const w={config:c,level:e,context:l,timestamp:a,app:"string"==typeof i&&i.length?i:void 0,separator:s,correlationId:m,rawMessage:u,filteredMessage:g,meta:f,metaString:d,stack:v,stackLabel:x,applyTheme:(t,r)=>o?z.theme(t,r,e):t},E=this.config("pattern"),O=c.pattern||"",_=h(E.length?E:O),k=L.render(w,_.keys);switch(this.config("format")){case"json":{const e=L.render(w,L.keys()),t={};return Object.entries(e).forEach(([e,r])=>{"meta"!==e&&(t[e]=r)}),w.meta&&(t.meta=w.meta),JSON.stringify(t)}case"raw":{let e=this.normalizePatternSpacing(y(_,k));return!_.includesMeta&&d&&(e=e?`${e} ${d}`:d),e}default:throw Error("Unsupported logging format: "+this.config("format"))}}formatMeta(e){try{return JSON.stringify(e)}catch(t){return e+""}}normalizePatternSpacing(e){return e.replace(/[ \t]{2,}/g," ").replace(/^[ \t]+|[ \t]+$/g,"")}log(t,r,n,o){const s=this.config("level");if(c[t]>c[s])return;let i;switch(t){case e.LogLevel.benchmark:case e.LogLevel.info:case e.LogLevel.verbose:i=console.log;break;case e.LogLevel.debug:i=console.debug;break;case e.LogLevel.error:i=console.error;break;case e.LogLevel.trace:i=console.trace;break;case e.LogLevel.warn:i=console.warn;break;case e.LogLevel.silly:i=console.debug;break;default:throw Error("Invalid log level")}i(this.createLog(t,r,n,o))}benchmark(t,r){this.log(e.LogLevel.benchmark,t,void 0,r)}silly(t,r=0,n){const o="number"==typeof r?r:0,s="number"==typeof r?n:r;this.config("verbose")<o||this.log(e.LogLevel.silly,t,void 0,s)}verbose(t,r=0,n){const o="number"==typeof r?r:0,s="number"==typeof r?n:r;this.config("verbose")<o||this.log(e.LogLevel.verbose,t,void 0,s)}info(t,r){this.log(e.LogLevel.info,t,void 0,r)}debug(t,r){this.log(e.LogLevel.debug,t,void 0,r)}error(t,r,n){let o,s;r instanceof Error?(o=r,s=n):s=r,this.log(e.LogLevel.error,t,o,s)}warn(t,r){this.log(e.LogLevel.warn,t,void 0,r)}trace(t,r){this.log(e.LogLevel.trace,t,void 0,r)}setConfig(e){this.conf={...this.conf||{},...e}}get root(){return[...this.baseContext]}clear(){return this.context=[...this.baseContext],this}}class z{static{this._factory=(e,t)=>{const r="string"==typeof $.app?[$.app]:[];return new D(e,t,r)}}static{this._config=$}constructor(){}static setFactory(e){z._factory=e,this.global=void 0}static setConfig(e){Object.entries(e).forEach(([e,t])=>{this._config[e]=t})}static getConfig(){return this._config}static get(){return this.ensureRoot()}static verbose(e,t=0,r){return this.get().verbose(e,t,r)}static info(e,t){return this.get().info(e,t)}static trace(e,t){return this.get().trace(e,t)}static debug(e,t){return this.get().debug(e,t)}static benchmark(e,t){return this.get().benchmark(e,t)}static silly(e,t=0,r){return this.get().silly(e,t,r)}static warn(e,t){return this.get().warn(e,t)}static error(e,t,r){return this.get().error(e,t,r)}static for(e,t,...r){const n=void 0!==t?[e,t]:[e];return(this.global?this.global:this.ensureRoot(r)).for(...n)}static because(e,t){let r=this.ensureRoot().for(e,this._config);return t&&(r=r.for(t)),r}static baseContext(){const e=this._config.app;return"string"==typeof e&&e.length?[e]:[]}static attachRootContext(e){const t=e.root&&Array.isArray(e.root)?[...e.root]:this.baseContext();return(!e.context||Array.isArray(e.context)&&0===e.context.length)&&(e.context=[...t]),e[K]=[...t],e}static ensureRoot(e=[]){if(!this.global){const t=this._factory(void 0,void 0,...e);this.global=this.attachRootContext(t)}return this.global}static theme(r,n,o,s=u){if(!this._config.style)return r;const i=s[n];if(!i||!Object.keys(i).length)return r;let a=i;const c=Object.assign({},e.LogLevel);return Object.keys(i)[0]in c&&(a=i[o]||{}),Object.keys(a).reduce((e,r)=>{const n=a[r];return n?((e,r,n)=>{try{const o=e;let s=t.style(o);function i(e,r=!1){let i=r?s.background:s.foreground;if(!Array.isArray(e))return i.call(s,n);switch(e.length){case 1:return i=r?s.bgColor256:s.color256,i(e[0]);case 3:return i=r?s.bgRgb:s.rgb,s.rgb(e[0],e[1],e[2]);default:return t.style(o)}}function a(e){s="number"==typeof e?s.style(e):s[e]}switch(r){case"bg":case"fg":return i(n).text;case"style":return Array.isArray(n)?n.forEach(a):a(n),s.text;default:return o}}catch(c){return e}})(e,r,n):e},r)}static register(e){return L.register(e)}static unregister(e){return L.unregister(e)}}class U{get log(){return this._log||(this._log=z.for(this)),this._log}constructor(){}}class J extends U{get log(){return super.log.for(this,{filters:[]})}}const Z="undefined"!=typeof globalThis&&"function"==typeof globalThis.performance?.now?()=>globalThis.performance.now():"undefined"!=typeof process&&"function"==typeof process.hrtime?.bigint?()=>{const e=process.hrtime.bigint();return Number(e)/1e6}:()=>Date.now();function q(e){const t=0>e?"-":"",r=Math.abs(e),n=Math.floor(r/36e5),o=Math.floor(r%36e5/6e4),s=Math.floor(r%6e4/1e3),i=Math.floor(r%1e3),a=(e,t)=>e.toString().padStart(t,"0");return`${t}${a(n,2)}:${a(o,2)}:${a(s,2)}.${a(i,3)}`}function B(t=e.LogLevel.info,r=0,n=(...e)=>"called with "+e,o){return(e,s,i)=>{if(!i||"number"==typeof i)throw Error("Logging decoration only applies to methods");const a=e instanceof U?e.log.for(e[s]):z.for(e).for(e[s]),c=a[t].bind(a),l=i.value;return i.value=new Proxy(l,{apply(e,t,s){c(n(...s),r);try{const r=Reflect.apply(e,t,s);return r instanceof Promise?r.then(e=>(o&&c(o(void 0,e)),e)).catch(e=>{throw o&&a.error(o(e)),e}):(o&&c(o(void 0,r)),r)}catch(e){throw o&&a.error(o(e)),e}}}),i}}function W(){return(e,t,r)=>{if(!r)throw Error("final decorator can only be used on methods");return r?.configurable&&(r.configurable=!1),r}}class H extends J{constructor(e,t){super(),this.regexp=e,this.replacement=t}match(e){const t=this.regexp.exec(e);return this.regexp.lastIndex=0,t}filter(e,t,r){const n=this.log.for(this.filter);if(!this.match(t))return t;try{return t.replace(this.regexp,this.replacement)}catch(e){n.error("PatternFilter replacement error: "+e)}return""}}n.__decorate([W(),n.__metadata("design:type",Function),n.__metadata("design:paramtypes",[String]),n.__metadata("design:returntype",void 0)],H.prototype,"match",null),e.BrowserEnvKey=o,e.DefaultLoggingConfig=g,e.DefaultPlaceholderWrappers=i,e.DefaultTheme=u,e.ENV_PATH_DELIMITER=s,e.Environment=C,e.LogFilter=J,e.LogParameterRegistry=f,e.LoggedClass=U,e.LoggedEnvironment=$,e.Logging=z,e.MiniLogger=D,e.NumericLogLevels=c,e.PACKAGE_NAME="@decaf-ts/logging",e.PatternFilter=H,e.ROOT_CONTEXT_SYMBOL=K,e.StopWatch=class{constructor(e=!1){this._startMs=null,this._elapsedMs=0,this._running=!1,this._laps=[],this._lastLapTotalMs=0,e&&this.start()}get running(){return this._running}get elapsedMs(){return this._running&&null!=this._startMs?this._elapsedMs+(Z()-this._startMs):this._elapsedMs}start(){return this._running||(this._running=!0,this._startMs=Z()),this}pause(){return this._running&&null!=this._startMs&&(this._elapsedMs+=Z()-this._startMs,this._startMs=null,this._running=!1),this}resume(){return this._running||(this._running=!0,this._startMs=Z()),this}stop(){return this.pause(),this._elapsedMs}reset(){const e=this._running;return this._startMs=e?Z():null,this._elapsedMs=0,this._laps=[],this._lastLapTotalMs=0,this}lap(e){const t=this.elapsedMs,r=t-this._lastLapTotalMs,n={index:this._laps.length,label:e,ms:r,totalMs:t};return this._laps.push(n),this._lastLapTotalMs=t,n}get laps(){return this._laps}toString(){return q(this.elapsedMs)}toJSON(){return{running:this._running,elapsedMs:this.elapsedMs,laps:this._laps.slice()}}},e.VERSION="0.17.0",e.benchmark=()=>(e,t,r)=>{if(!r||"number"==typeof r)throw Error("benchmark decoration only applies to methods");const n=e instanceof U?e.log.for(e[t]):z.for(e).for(e[t]),o=r.value;return r.value=new Proxy(o,{apply(e,t,r){const o=Z();try{const s=Reflect.apply(e,t,r);return s instanceof Promise?s.then(e=>(n.benchmark(`completed in ${Z()-o}ms`),e)).catch(e=>{throw n.benchmark(`failed in ${Z()-o}ms`),e}):(n.benchmark(`completed in ${Z()-o}ms`),s)}catch(e){throw n.benchmark(`failed in ${Z()-o}ms`),e}}}),r},e.compileLogPattern=h,e.debug=()=>B(e.LogLevel.debug,0,(...e)=>"called with "+e,(e,t)=>e?"Failed with: "+e:t?"Completed with "+JSON.stringify(t):"completed"),e.escapeRegExp=k,e.final=W,e.formatMs=q,e.getObjectName=F,e.info=()=>B(e.LogLevel.info),e.isBrowser=M,e.isClass=T,e.isFunction=I,e.isInstance=N,e.isMethod=V,e.log=B,e.logParameterRegistry=L,e.now=Z,e.padEnd=(e,t,r=" ")=>{if(1!==r.length)throw Error("Invalid character length for padding. must be one!");return e.padEnd(t,r)},e.patchPlaceholders=(e,t,r=i[0],n=i[1],o="g")=>E(e,Object.entries(t).reduce((e,[t,o])=>(e[`${r}${t}${n}`]=o,e),{}),o),e.patchString=E,e.renderPattern=y,e.sf=j,e.silly=()=>B(e.LogLevel.silly),e.stringFormat=A,e.toCamelCase=e=>e.replace(/(?:^\w|[A-Z]|\b\w)/g,(e,t)=>0===t?e.toLowerCase():e.toUpperCase()).replace(/\s+/g,""),e.toENVFormat=O,e.toKebabCase=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase(),e.toPascalCase=e=>e.replace(/(?:^\w|[A-Z]|\b\w)/g,e=>e.toUpperCase()).replace(/\s+/g,""),e.toSnakeCase=_,e.trace=()=>B(e.LogLevel.trace),e.verbose=(t=0)=>(t||(t=0),B(e.LogLevel.verbose,t)),Object.keys(t).forEach(r=>{"default"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:()=>t[r]})})},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("styled-string-builder"),require("typed-object-accumulator"),require("tslib")):"function"==typeof define&&define.amd?define(["exports","styled-string-builder","typed-object-accumulator","tslib"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).logging={},e.styledStringBuilder,e.typedObjectAccumulator,e.tslib); | ||
| //# sourceMappingURL=logging.cjs.map |
@@ -43,3 +43,3 @@ "use strict"; | ||
| */ | ||
| exports.VERSION = "0.16.0"; | ||
| exports.VERSION = "0.17.0"; | ||
| /** | ||
@@ -46,0 +46,0 @@ * @description Current package version string. |
+1
-1
@@ -26,3 +26,3 @@ /** | ||
| */ | ||
| export const VERSION = "0.16.0"; | ||
| export const VERSION = "0.17.0"; | ||
| /** | ||
@@ -29,0 +29,0 @@ * @description Current package version string. |
+1
-1
| { | ||
| "name": "@decaf-ts/logging", | ||
| "version": "0.17.0", | ||
| "version": "0.18.0", | ||
| "description": "simple winston inspired wrapper for cross lib logging", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package