@decaf-ts/logging 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/logging.cjs +1 -1
- package/lib/cjs/index.cjs +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/LoggedClass.d.cts +1 -1
- package/lib/types/LoggedClass.d.mts +1 -1
- package/lib/types/constants.d.cts +1 -1
- package/lib/types/constants.d.mts +1 -1
- package/lib/types/decorators.d.cts +1 -1
- package/lib/types/decorators.d.mts +1 -1
- package/lib/types/filters/LogFilter.d.cts +2 -2
- package/lib/types/filters/LogFilter.d.mts +2 -2
- package/lib/types/filters/PatternFilter.d.cts +2 -2
- package/lib/types/filters/PatternFilter.d.mts +2 -2
- package/lib/types/filters/index.d.cts +2 -2
- package/lib/types/filters/index.d.mts +2 -2
- package/lib/types/index.d.cts +12 -12
- package/lib/types/index.d.mts +12 -12
- package/lib/types/logParameters.d.cts +2 -2
- package/lib/types/logParameters.d.mts +2 -2
- package/lib/types/logging.d.cts +6 -6
- package/lib/types/logging.d.mts +6 -6
- package/lib/types/pino/index.d.cts +1 -1
- package/lib/types/pino/index.d.mts +1 -1
- package/lib/types/pino/pino.d.cts +3 -3
- package/lib/types/pino/pino.d.mts +3 -3
- package/lib/types/types.d.cts +1 -1
- package/lib/types/types.d.mts +1 -1
- package/lib/types/winston/index.d.cts +1 -1
- package/lib/types/winston/index.d.mts +1 -1
- package/lib/types/winston/winston.d.cts +3 -3
- package/lib/types/winston/winston.d.mts +3 -3
- package/package.json +1 -1
- package/lib/types/LoggedClass.d.ts +0 -39
- package/lib/types/constants.d.ts +0 -104
- package/lib/types/decorators.d.ts +0 -109
- package/lib/types/environment.d.ts +0 -120
- package/lib/types/filters/LogFilter.d.ts +0 -43
- package/lib/types/filters/PatternFilter.d.ts +0 -56
- package/lib/types/filters/index.d.ts +0 -7
- package/lib/types/index.d.ts +0 -34
- package/lib/types/logParameters.d.ts +0 -56
- package/lib/types/logging.d.ts +0 -373
- package/lib/types/pino/index.d.ts +0 -7
- package/lib/types/pino/pino.d.ts +0 -29
- package/lib/types/text.d.ts +0 -118
- package/lib/types/time.d.ts +0 -151
- package/lib/types/types.d.ts +0 -287
- package/lib/types/utils.d.ts +0 -48
- package/lib/types/web.d.ts +0 -8
- package/lib/types/winston/index.d.ts +0 -7
- package/lib/types/winston/winston.d.ts +0 -47
package/dist/logging.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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.18.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);
|
|
1
|
+
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.20.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);
|
|
2
2
|
//# sourceMappingURL=logging.cjs.map
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ __exportStar(require("styled-string-builder"), exports);
|
|
|
40
40
|
* @type {string}
|
|
41
41
|
* @memberOf module:Logging
|
|
42
42
|
*/
|
|
43
|
-
exports.VERSION = "0.
|
|
43
|
+
exports.VERSION = "0.20.0";
|
|
44
44
|
/**
|
|
45
45
|
* @description Current package version string.
|
|
46
46
|
* @summary Stores the package version for diagnostics and compatibility checks.
|
package/lib/esm/index.js
CHANGED
|
@@ -23,7 +23,7 @@ export * from "styled-string-builder";
|
|
|
23
23
|
* @type {string}
|
|
24
24
|
* @memberOf module:Logging
|
|
25
25
|
*/
|
|
26
|
-
export const VERSION = "0.
|
|
26
|
+
export const VERSION = "0.20.0";
|
|
27
27
|
/**
|
|
28
28
|
* @description Current package version string.
|
|
29
29
|
* @summary Stores the package version for diagnostics and compatibility checks.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger } from "./types.
|
|
1
|
+
import { Logger } from "./types.d.cts";
|
|
2
2
|
/**
|
|
3
3
|
* @description A base class that provides a ready-to-use logger instance.
|
|
4
4
|
* @summary This class supplies inheriting classes with a lazily created, context-aware {@link Logger} via the protected `log` getter. This promotes consistent, structured logging without the need for manual wiring.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger } from "./types.
|
|
1
|
+
import { Logger } from "./types.d.mts";
|
|
2
2
|
/**
|
|
3
3
|
* @description A base class that provides a ready-to-use logger instance.
|
|
4
4
|
* @summary This class supplies inheriting classes with a lazily created, context-aware {@link Logger} via the protected `log` getter. This promotes consistent, structured logging without the need for manual wiring.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoggingConfig, Theme } from "./types.
|
|
1
|
+
import { LoggingConfig, Theme } from "./types.d.cts";
|
|
2
2
|
/**
|
|
3
3
|
* @description The global key that is used to store environment variables in browser contexts.
|
|
4
4
|
* @summary This enables the logging environment helpers to locate serialized environment configuration on `globalThis`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoggingConfig, Theme } from "./types.
|
|
1
|
+
import { LoggingConfig, Theme } from "./types.d.mts";
|
|
2
2
|
/**
|
|
3
3
|
* @description The global key that is used to store environment variables in browser contexts.
|
|
4
4
|
* @summary This enables the logging environment helpers to locate serialized environment configuration on `globalThis`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Logger, LoggingConfig, LoggingFilter } from "../types.
|
|
2
|
-
import { LoggedClass } from "../LoggedClass.
|
|
1
|
+
import { Logger, LoggingConfig, LoggingFilter } from "../types.d.cts";
|
|
2
|
+
import { LoggedClass } from "../LoggedClass.d.cts";
|
|
3
3
|
/**
|
|
4
4
|
* @description A base class for message filters that can be plugged into the logging pipeline.
|
|
5
5
|
* @summary This class extends {@link LoggedClass} to supply a scoped logger, and defines the contract that is required by {@link LoggingFilter} implementers that transform or drop log messages before emission.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Logger, LoggingConfig, LoggingFilter } from "../types.
|
|
2
|
-
import { LoggedClass } from "../LoggedClass.
|
|
1
|
+
import { Logger, LoggingConfig, LoggingFilter } from "../types.d.mts";
|
|
2
|
+
import { LoggedClass } from "../LoggedClass.d.mts";
|
|
3
3
|
/**
|
|
4
4
|
* @description A base class for message filters that can be plugged into the logging pipeline.
|
|
5
5
|
* @summary This class extends {@link LoggedClass} to supply a scoped logger, and defines the contract that is required by {@link LoggingFilter} implementers that transform or drop log messages before emission.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LogFilter } from "./LogFilter.
|
|
2
|
-
import { LoggingConfig } from "../types.
|
|
1
|
+
import { LogFilter } from "./LogFilter.d.cts";
|
|
2
|
+
import { LoggingConfig } from "../types.d.cts";
|
|
3
3
|
/**
|
|
4
4
|
* @description A replacement callback that is used to transform RegExp matches.
|
|
5
5
|
* @summary This function receives the matched substring and additional capture arguments, and returns the replacement text that will be injected into the log message.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LogFilter } from "./LogFilter.
|
|
2
|
-
import { LoggingConfig } from "../types.
|
|
1
|
+
import { LogFilter } from "./LogFilter.d.mts";
|
|
2
|
+
import { LoggingConfig } from "../types.d.mts";
|
|
3
3
|
/**
|
|
4
4
|
* @description A replacement callback that is used to transform RegExp matches.
|
|
5
5
|
* @summary This function receives the matched substring and additional capture arguments, and returns the replacement text that will be injected into the log message.
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* @summary This file exports all the necessary components for the filters functionality, including LogFilter and PatternFilter.
|
|
4
4
|
* @module logging/filters
|
|
5
5
|
*/
|
|
6
|
-
export * from "./LogFilter.
|
|
7
|
-
export * from "./PatternFilter.
|
|
6
|
+
export * from "./LogFilter.d.cts";
|
|
7
|
+
export * from "./PatternFilter.d.cts";
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* @summary This file exports all the necessary components for the filters functionality, including LogFilter and PatternFilter.
|
|
4
4
|
* @module logging/filters
|
|
5
5
|
*/
|
|
6
|
-
export * from "./LogFilter.
|
|
7
|
-
export * from "./PatternFilter.
|
|
6
|
+
export * from "./LogFilter.d.mts";
|
|
7
|
+
export * from "./PatternFilter.d.mts";
|
package/lib/types/index.d.cts
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
* @description A comprehensive and versatile logging toolkit for both browser and Node.js environments.
|
|
4
4
|
* @summary This module provides a complete logging solution, exposing {@link Logging} and {@link MiniLogger} for runtime logging. It also includes decorators like {@link log} for method instrumentation, and various utilities such as {@link PatternFilter}, {@link StopWatch}, and {@link LoggedEnvironment} to help build configurable and theme-aware log pipelines.
|
|
5
5
|
*/
|
|
6
|
-
export * from "./filters/index.
|
|
7
|
-
export * from "./constants.
|
|
8
|
-
export * from "./decorators.
|
|
9
|
-
export * from "./environment.
|
|
10
|
-
export * from "./LoggedClass.
|
|
11
|
-
export * from "./logging.
|
|
12
|
-
export * from "./logParameters.
|
|
13
|
-
export * from "./text.
|
|
14
|
-
export * from "./time.
|
|
15
|
-
export * from "./types.
|
|
16
|
-
export * from "./web.
|
|
17
|
-
export * from "./utils.
|
|
6
|
+
export * from "./filters/index.d.cts";
|
|
7
|
+
export * from "./constants.d.cts";
|
|
8
|
+
export * from "./decorators.d.cts";
|
|
9
|
+
export * from "./environment.d.cts";
|
|
10
|
+
export * from "./LoggedClass.d.cts";
|
|
11
|
+
export * from "./logging.d.cts";
|
|
12
|
+
export * from "./logParameters.d.cts";
|
|
13
|
+
export * from "./text.d.cts";
|
|
14
|
+
export * from "./time.d.cts";
|
|
15
|
+
export * from "./types.d.cts";
|
|
16
|
+
export * from "./web.d.cts";
|
|
17
|
+
export * from "./utils.d.cts";
|
|
18
18
|
export * from "styled-string-builder";
|
|
19
19
|
/**
|
|
20
20
|
* @description Current package version string.
|
package/lib/types/index.d.mts
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
* @description A comprehensive and versatile logging toolkit for both browser and Node.js environments.
|
|
4
4
|
* @summary This module provides a complete logging solution, exposing {@link Logging} and {@link MiniLogger} for runtime logging. It also includes decorators like {@link log} for method instrumentation, and various utilities such as {@link PatternFilter}, {@link StopWatch}, and {@link LoggedEnvironment} to help build configurable and theme-aware log pipelines.
|
|
5
5
|
*/
|
|
6
|
-
export * from "./filters/index.
|
|
7
|
-
export * from "./constants.
|
|
8
|
-
export * from "./decorators.
|
|
9
|
-
export * from "./environment.
|
|
10
|
-
export * from "./LoggedClass.
|
|
11
|
-
export * from "./logging.
|
|
12
|
-
export * from "./logParameters.
|
|
13
|
-
export * from "./text.
|
|
14
|
-
export * from "./time.
|
|
15
|
-
export * from "./types.
|
|
16
|
-
export * from "./web.
|
|
17
|
-
export * from "./utils.
|
|
6
|
+
export * from "./filters/index.d.mts";
|
|
7
|
+
export * from "./constants.d.mts";
|
|
8
|
+
export * from "./decorators.d.mts";
|
|
9
|
+
export * from "./environment.d.mts";
|
|
10
|
+
export * from "./LoggedClass.d.mts";
|
|
11
|
+
export * from "./logging.d.mts";
|
|
12
|
+
export * from "./logParameters.d.mts";
|
|
13
|
+
export * from "./text.d.mts";
|
|
14
|
+
export * from "./time.d.mts";
|
|
15
|
+
export * from "./types.d.mts";
|
|
16
|
+
export * from "./web.d.mts";
|
|
17
|
+
export * from "./utils.d.mts";
|
|
18
18
|
export * from "styled-string-builder";
|
|
19
19
|
/**
|
|
20
20
|
* @description Current package version string.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LogLevel } from "./constants.
|
|
2
|
-
import { LogMeta, LoggingConfig } from "./types.
|
|
1
|
+
import { LogLevel } from "./constants.d.cts";
|
|
2
|
+
import { LogMeta, LoggingConfig } from "./types.d.cts";
|
|
3
3
|
export type LogParameterPayload = {
|
|
4
4
|
config: LoggingConfig;
|
|
5
5
|
level: LogLevel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LogLevel } from "./constants.
|
|
2
|
-
import { LogMeta, LoggingConfig } from "./types.
|
|
1
|
+
import { LogLevel } from "./constants.d.mts";
|
|
2
|
+
import { LogMeta, LoggingConfig } from "./types.d.mts";
|
|
3
3
|
export type LogParameterPayload = {
|
|
4
4
|
config: LoggingConfig;
|
|
5
5
|
level: LogLevel;
|
package/lib/types/logging.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LoggerFactory, LoggingConfig, LoggingContext, LoggingFilter, LogMeta, StringLike, Theme, Logger } from "./types.
|
|
2
|
-
import { LogLevel } from "./constants.
|
|
3
|
-
import { LogParameterDescriptor } from "./logParameters.
|
|
4
|
-
import { LoggedEnvironment } from "./environment.
|
|
1
|
+
import { LoggerFactory, LoggingConfig, LoggingContext, LoggingFilter, LogMeta, StringLike, Theme, Logger } from "./types.d.cts";
|
|
2
|
+
import { LogLevel } from "./constants.d.cts";
|
|
3
|
+
import { LogParameterDescriptor } from "./logParameters.d.cts";
|
|
4
|
+
import { LoggedEnvironment } from "./environment.d.cts";
|
|
5
5
|
export declare const ROOT_CONTEXT_SYMBOL: unique symbol;
|
|
6
6
|
/**
|
|
7
7
|
* @description A minimal logger implementation.
|
|
@@ -368,6 +368,6 @@ export declare class Logging {
|
|
|
368
368
|
* end
|
|
369
369
|
*/
|
|
370
370
|
static theme(text: string, type: keyof Theme | keyof LogLevel, loggerLevel: LogLevel, template?: Theme): string;
|
|
371
|
-
static register(descriptor: LogParameterDescriptor): import("./logParameters.
|
|
372
|
-
static unregister(key: string): import("./logParameters.
|
|
371
|
+
static register(descriptor: LogParameterDescriptor): import("./logParameters.d.cts").LogParameterRegistry;
|
|
372
|
+
static unregister(key: string): import("./logParameters.d.cts").LogParameterRegistry;
|
|
373
373
|
}
|
package/lib/types/logging.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LoggerFactory, LoggingConfig, LoggingContext, LoggingFilter, LogMeta, StringLike, Theme, Logger } from "./types.
|
|
2
|
-
import { LogLevel } from "./constants.
|
|
3
|
-
import { LogParameterDescriptor } from "./logParameters.
|
|
4
|
-
import { LoggedEnvironment } from "./environment.
|
|
1
|
+
import { LoggerFactory, LoggingConfig, LoggingContext, LoggingFilter, LogMeta, StringLike, Theme, Logger } from "./types.d.mts";
|
|
2
|
+
import { LogLevel } from "./constants.d.mts";
|
|
3
|
+
import { LogParameterDescriptor } from "./logParameters.d.mts";
|
|
4
|
+
import { LoggedEnvironment } from "./environment.d.mts";
|
|
5
5
|
export declare const ROOT_CONTEXT_SYMBOL: unique symbol;
|
|
6
6
|
/**
|
|
7
7
|
* @description A minimal logger implementation.
|
|
@@ -368,6 +368,6 @@ export declare class Logging {
|
|
|
368
368
|
* end
|
|
369
369
|
*/
|
|
370
370
|
static theme(text: string, type: keyof Theme | keyof LogLevel, loggerLevel: LogLevel, template?: Theme): string;
|
|
371
|
-
static register(descriptor: LogParameterDescriptor): import("./logParameters.
|
|
372
|
-
static unregister(key: string): import("./logParameters.
|
|
371
|
+
static register(descriptor: LogParameterDescriptor): import("./logParameters.d.mts").LogParameterRegistry;
|
|
372
|
+
static unregister(key: string): import("./logParameters.d.mts").LogParameterRegistry;
|
|
373
373
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger as PinoBaseLogger } from "pino";
|
|
2
|
-
import { MiniLogger } from "../logging.
|
|
3
|
-
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types.
|
|
4
|
-
import { LogLevel } from "../constants.
|
|
2
|
+
import { MiniLogger } from "../logging.d.cts";
|
|
3
|
+
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types.d.cts";
|
|
4
|
+
import { LogLevel } from "../constants.d.cts";
|
|
5
5
|
/**
|
|
6
6
|
* @description A logger that is powered by the Pino logging library.
|
|
7
7
|
* @summary This class extends {@link MiniLogger} and uses Pino as its underlying logging engine.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger as PinoBaseLogger } from "pino";
|
|
2
|
-
import { MiniLogger } from "../logging.
|
|
3
|
-
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types.
|
|
4
|
-
import { LogLevel } from "../constants.
|
|
2
|
+
import { MiniLogger } from "../logging.d.mts";
|
|
3
|
+
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types.d.mts";
|
|
4
|
+
import { LogLevel } from "../constants.d.mts";
|
|
5
5
|
/**
|
|
6
6
|
* @description A logger that is powered by the Pino logging library.
|
|
7
7
|
* @summary This class extends {@link MiniLogger} and uses Pino as its underlying logging engine.
|
package/lib/types/types.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { styles } from "styled-string-builder";
|
|
2
|
-
import { LoggingMode, LogLevel } from "./constants.
|
|
2
|
+
import { LoggingMode, LogLevel } from "./constants.d.cts";
|
|
3
3
|
/**
|
|
4
4
|
* @description A string-compatible value that can be accepted by the logging APIs.
|
|
5
5
|
* @summary Represents either a literal string or an object that has a `toString()` method. This allows for the lazy stringification of complex payloads.
|
package/lib/types/types.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { styles } from "styled-string-builder";
|
|
2
|
-
import { LoggingMode, LogLevel } from "./constants.
|
|
2
|
+
import { LoggingMode, LogLevel } from "./constants.d.mts";
|
|
3
3
|
/**
|
|
4
4
|
* @description A string-compatible value that can be accepted by the logging APIs.
|
|
5
5
|
* @summary Represents either a literal string or an object that has a `toString()` method. This allows for the lazy stringification of complex payloads.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import winston from "winston";
|
|
2
|
-
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types.
|
|
3
|
-
import { MiniLogger } from "../logging.
|
|
4
|
-
import { LogLevel } from "../constants.
|
|
2
|
+
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types.d.cts";
|
|
3
|
+
import { MiniLogger } from "../logging.d.cts";
|
|
4
|
+
import { LogLevel } from "../constants.d.cts";
|
|
5
5
|
/**
|
|
6
6
|
* @description A logger implementation that uses Winston.
|
|
7
7
|
* @summary This class extends {@link MiniLogger} to provide logging functionality using the Winston library. It configures Winston with the appropriate transports and formats based on the logging configuration.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import winston from "winston";
|
|
2
|
-
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types.
|
|
3
|
-
import { MiniLogger } from "../logging.
|
|
4
|
-
import { LogLevel } from "../constants.
|
|
2
|
+
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types.d.mts";
|
|
3
|
+
import { MiniLogger } from "../logging.d.mts";
|
|
4
|
+
import { LogLevel } from "../constants.d.mts";
|
|
5
5
|
/**
|
|
6
6
|
* @description A logger implementation that uses Winston.
|
|
7
7
|
* @summary This class extends {@link MiniLogger} to provide logging functionality using the Winston library. It configures Winston with the appropriate transports and formats based on the logging configuration.
|
package/package.json
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Logger } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* @description A base class that provides a ready-to-use logger instance.
|
|
4
|
-
* @summary This class supplies inheriting classes with a lazily created, context-aware {@link Logger} via the protected `log` getter. This promotes consistent, structured logging without the need for manual wiring.
|
|
5
|
-
* @class LoggedClass
|
|
6
|
-
* @example
|
|
7
|
-
* class UserService extends LoggedClass {
|
|
8
|
-
* create(user: User) {
|
|
9
|
-
* this.log.info(`Creating user ${user.id}`);
|
|
10
|
-
* }
|
|
11
|
-
* }
|
|
12
|
-
*
|
|
13
|
-
* const svc = new UserService();
|
|
14
|
-
* svc.create({ id: "42" });
|
|
15
|
-
* @mermaid
|
|
16
|
-
* sequenceDiagram
|
|
17
|
-
* participant Client
|
|
18
|
-
* participant Instance as Subclass Instance
|
|
19
|
-
* participant Getter as LoggedClass.log
|
|
20
|
-
* participant Logging as Logging
|
|
21
|
-
* participant Logger as Logger
|
|
22
|
-
*
|
|
23
|
-
* Client->>Instance: call someMethod()
|
|
24
|
-
* Instance->>Getter: access this.log
|
|
25
|
-
* Getter->>Logging: Logging.for(this)
|
|
26
|
-
* Logging-->>Getter: return Logger
|
|
27
|
-
* Getter-->>Instance: return Logger
|
|
28
|
-
* Instance->>Logger: info/debug/error(...)
|
|
29
|
-
*/
|
|
30
|
-
export declare abstract class LoggedClass {
|
|
31
|
-
private _log?;
|
|
32
|
-
/**
|
|
33
|
-
* @description Lazily provides a context-aware logger for the current instance.
|
|
34
|
-
* @summary This method calls {@link Logging.for} with the subclass instance to obtain a logger whose context matches the subclass name.
|
|
35
|
-
* @return {Logger} A logger that is bound to the subclass context.
|
|
36
|
-
*/
|
|
37
|
-
protected get log(): Logger;
|
|
38
|
-
protected constructor();
|
|
39
|
-
}
|
package/lib/types/constants.d.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { LoggingConfig, Theme } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* @description The global key that is used to store environment variables in browser contexts.
|
|
4
|
-
* @summary This enables the logging environment helpers to locate serialized environment configuration on `globalThis`.
|
|
5
|
-
* @const {string} BrowserEnvKey
|
|
6
|
-
* @memberOf module:Logging
|
|
7
|
-
*/
|
|
8
|
-
export declare const BrowserEnvKey = "ENV";
|
|
9
|
-
/**
|
|
10
|
-
* @description The delimiter that is used for composing nested environment variable names.
|
|
11
|
-
* @summary This joins parent and child keys when mapping object paths to ENV strings.
|
|
12
|
-
* @const {string} ENV_PATH_DELIMITER
|
|
13
|
-
* @memberOf module:Logging
|
|
14
|
-
*/
|
|
15
|
-
export declare const ENV_PATH_DELIMITER = "__";
|
|
16
|
-
/**
|
|
17
|
-
* @description The default prefix and suffix that are used for template placeholders.
|
|
18
|
-
* @summary This provides wrapper strings that are applied when interpolating messages with {@link patchPlaceholders}.
|
|
19
|
-
* @const {string[]} DefaultPlaceholderWrappers
|
|
20
|
-
* @memberOf module:Logging
|
|
21
|
-
*/
|
|
22
|
-
export declare const DefaultPlaceholderWrappers: string[];
|
|
23
|
-
/**
|
|
24
|
-
* @description An enum for log levels.
|
|
25
|
-
* @summary Defines the different levels of logging for the application.
|
|
26
|
-
* @enum {string}
|
|
27
|
-
* @readonly
|
|
28
|
-
* @memberOf module:Logging
|
|
29
|
-
*/
|
|
30
|
-
export declare enum LogLevel {
|
|
31
|
-
/** @description Benchmark events that capture performance metrics. */
|
|
32
|
-
benchmark = "benchmark",
|
|
33
|
-
/** @description Error events that indicate failures requiring attention. */
|
|
34
|
-
error = "error",
|
|
35
|
-
/** @description Warning events that may indicate issues. */
|
|
36
|
-
warn = "warn",
|
|
37
|
-
/** @description Informational events describing normal operation. */
|
|
38
|
-
info = "info",
|
|
39
|
-
/** @description Verbose diagnostic information for detailed tracing. */
|
|
40
|
-
verbose = "verbose",
|
|
41
|
-
/** @description Debug or trace details aimed at developers. */
|
|
42
|
-
debug = "debug",
|
|
43
|
-
/** @description trace details aimed at developers */
|
|
44
|
-
trace = "trace",
|
|
45
|
-
/** @description Extremely chatty or playful log entries. */
|
|
46
|
-
silly = "silly"
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @description The numeric values that are associated with log levels.
|
|
50
|
-
* @summary This provides a numeric representation of log levels for comparison and filtering.
|
|
51
|
-
* @typedef {object} NumericLogLevelsShape
|
|
52
|
-
* @property {number} benchmark - The numeric value for the benchmark level (0).
|
|
53
|
-
* @property {number} error - The numeric value for the error level (3).
|
|
54
|
-
* @property {number} warn - The numeric value for the warn level (6).
|
|
55
|
-
* @property {number} info - The numeric value for the info level (9).
|
|
56
|
-
* @property {number} verbose - The numeric value for the verbose level (12).
|
|
57
|
-
* @property {number} debug - The numeric value for the debug level (15).
|
|
58
|
-
* @property {number} trace - The numeric value for the trace level (18).
|
|
59
|
-
* @property {number} silly - The numeric value for the silly level (21).
|
|
60
|
-
* @memberOf module:Logging
|
|
61
|
-
*/
|
|
62
|
-
/**
|
|
63
|
-
* @description The numeric values that are associated with log levels.
|
|
64
|
-
* @summary This provides a numeric representation of log levels for comparison and filtering.
|
|
65
|
-
* @const {NumericLogLevelsShape} NumericLogLevels
|
|
66
|
-
* @memberOf module:Logging
|
|
67
|
-
*/
|
|
68
|
-
export declare const NumericLogLevels: {
|
|
69
|
-
benchmark: number;
|
|
70
|
-
error: number;
|
|
71
|
-
warn: number;
|
|
72
|
-
info: number;
|
|
73
|
-
verbose: number;
|
|
74
|
-
debug: number;
|
|
75
|
-
trace: number;
|
|
76
|
-
silly: number;
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* @description An enum for logging output modes.
|
|
80
|
-
* @summary Defines the different output formats for log messages.
|
|
81
|
-
* @enum {string}
|
|
82
|
-
* @readonly
|
|
83
|
-
* @memberOf module:Logging
|
|
84
|
-
*/
|
|
85
|
-
export declare enum LoggingMode {
|
|
86
|
-
/** Raw text format for human readability */
|
|
87
|
-
RAW = "raw",
|
|
88
|
-
/** JSON format for machine parsing */
|
|
89
|
-
JSON = "json"
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @description The default theme for styling log output.
|
|
93
|
-
* @summary Defines the default color and style settings for various components of log messages.
|
|
94
|
-
* @const {Theme} DefaultTheme
|
|
95
|
-
* @memberOf module:Logging
|
|
96
|
-
*/
|
|
97
|
-
export declare const DefaultTheme: Theme;
|
|
98
|
-
/**
|
|
99
|
-
* @description The default configuration for logging.
|
|
100
|
-
* @summary Defines the default settings for the logging system, including verbosity, log level, styling, and timestamp format.
|
|
101
|
-
* @const {LoggingConfig} DefaultLoggingConfig
|
|
102
|
-
* @memberOf module:Logging
|
|
103
|
-
*/
|
|
104
|
-
export declare const DefaultLoggingConfig: LoggingConfig;
|