@zenflux/core 0.1.25 → 0.1.26
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.
|
@@ -4,7 +4,7 @@ type LoggerOptions = {
|
|
|
4
4
|
skipEventBusHook?: boolean;
|
|
5
5
|
repeatedly?: boolean;
|
|
6
6
|
};
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class ZenFluxLogger extends Logger {
|
|
8
8
|
private prepareLog;
|
|
9
9
|
log(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
10
10
|
info(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
@@ -13,5 +13,5 @@ export declare class EyeNoteLogger extends Logger {
|
|
|
13
13
|
error(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
14
14
|
admin(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
15
15
|
}
|
|
16
|
-
export declare const createLogger: (owner: string | object, options?: LoggerOptions) =>
|
|
16
|
+
export declare const createLogger: (owner: string | object, options?: LoggerOptions) => ZenFluxLogger;
|
|
17
17
|
export {};
|
package/dist/zenflux-core.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bundled with love using the help of @zenflux/cli toolkit v0.1.43
|
|
3
|
-
* Bundle name: @zenflux/core fileName: 'zenflux-core', built at
|
|
3
|
+
* Bundle name: @zenflux/core fileName: 'zenflux-core', built at Tue Feb 03 2026 11:53:40 GMT+0200 (Israel Standard Time)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
@@ -105,7 +105,7 @@ let SimpleEventEmitter=class SimpleEventEmitter{listeners=new Map;on(event,callb
|
|
|
105
105
|
|
|
106
106
|
const DEFAULT_LOG_PREFIX=pc.white("⚪ - [LOG]"),DEFAULT_INFO_PREFIX=pc.blue("🔵 - [INFO]"),DEFAULT_DEBUG_PREFIX=pc.gray("🟤 - [DEBUG]"),DEFAULT_WARN_PREFIX=pc.yellow("🟡 - [WARN]"),DEFAULT_ERROR_PREFIX=pc.red("🔴 - [ERROR]"),DEFAULT_ADMIN_PREFIX=pc.bold("🟣 - [ADMIN]");const LEVEL_LABELS={log:"LOG",info:"INFO",debug:"DEBUG",warn:"WARN",error:"ERROR",admin:"ADMIN"};const registeredNames={};class Logger extends LoggerBrowserInfra{static lastLogTime=Date.now();static timestampFormat=getLoggerTimeFormat();ownerName;messagePrefixes=[];config={};static setTimestampFormat(format){Logger.timestampFormat=(format||"").trim();}static getTimestampFormat(){return Logger.timestampFormat}static getName(){return "ZenFlux/Core/Modules/Logger"}static getLogLevelString(){return getLoggerLogLevelString()}static getLogLevel(){return getLoggerLogLevel()}static attachOutputListener(listener){return LoggerBrowserInfra.attachOutputSubscriber(listener)}static isDebugEnabled(){return isLoggerDebugEnabled()}constructor(owner,options){const{repeatedly=false,skipEventBusHook}=options||{};super(owner,{repeatedly});this.config={skipEventBusHook};this.ownerName=Logger.resolveOwnerName(owner);if(registeredNames[this.ownerName]){throw new Error(`Logger for '${this.ownerName}' already exists`)}registeredNames[this.ownerName]=true;if(isLoggerDisabled()){this.disableLoggers();return}if(isLoggerPreviousSourceDisabled()){this.getPreviousSource=()=>"";}switch(getLoggerLogLevel()){case 0:this.error=()=>{};case 1:this.warn=()=>{};case 2:this.admin=()=>{};case 3:this.info=()=>{};case 4:this.log=()=>{};case 5:this.debug=()=>{};}if(!this.config.skipEventBusHook){EventBus.$.registerMultiInstances(this,[this.outputEvent]);}}addMessagePrefix(prefix){this.messagePrefixes.push(prefix);}log(caller,message,...params){this.writeLog("log",DEFAULT_LOG_PREFIX,caller,message,...params);}info(caller,message,...params){this.writeLog("info",DEFAULT_INFO_PREFIX,caller,message,...params);}debug(caller,message,...params){this.writeLog("debug",DEFAULT_DEBUG_PREFIX,caller,message,...params);}warn(caller,message,...params){this.writeLog("warn",DEFAULT_WARN_PREFIX,caller,message,...params);}error(caller,message,...params){this.writeLog("error",DEFAULT_ERROR_PREFIX,caller,message,...params);}admin(caller,message,...params){this.writeLog("admin",DEFAULT_ADMIN_PREFIX,caller,message,...params);}startsEmpty(caller){this.printFunctionNotify("▶",caller,"");}startsWith(caller,params){this.printObjectEfficient("▶",caller,params);}dump(caller,params={},notice=""){for(const key in params){if(typeof params[key]==="object"){params[key]=JSON.stringify(LoggerBrowserInfra.useObjectMapper(params[key]),reduceCircularReferences());}this.printInLineElement("dp",caller,key,params[key],notice);}}drop(caller,according,data){for(const key in according){this.printInLineElement("dr",caller,key,according[key],"corresponding");}this.output(data);}throw(caller,output,name="null",params={}){this.printFunctionNotify("tw",caller,output);if(params){this.printInNextLineObject("tw",caller,name,params);}throw new Error().stack}beep(){console.log("\x07");}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}outputEvent(_prefix,_timeDiff,_source,_messagePrefix,_message,_params){}static resolveOwnerName(owner){if(typeof owner==="string"){return owner}if(owner instanceof ObjectBase){return owner.getName()}if(owner&&typeof owner.getName==="function"){return owner.getName()}return "UnknownOwner"}disableLoggers(){this.error=()=>{};this.warn=()=>{};this.admin=()=>{};this.info=()=>{};this.log=()=>{};this.debug=()=>{};}getStackTrace(){const stackTrace=(new Error().stack||"").split("\n");const stackLines=stackTrace.slice(1);const stackRegex=/ at (.+?) \((.+?)\)/;const result=[];for(const line of stackLines){const match=line.match(stackRegex);if(match){const[,context,file]=match;const parsedLine={context,file};if(line.startsWith("new")){parsedLine.isNew=true;parsedLine.object=context.split(" ")[1];}else if(context!=="Object.<anonymous>"){parsedLine.object=context;}result.push(parsedLine);}}return result}getPreviousSource(){const stack=this.getStackTrace().filter(line=>line.file.includes("/src/")).filter(line=>!line.file.includes("logger.ts")).filter(line=>!line.file.includes("debugger.ts")).filter(line=>!line.file.includes("/node_modules/"));let previousSource="";const previousCaller=stack[1]?.object?.split(".");if(previousCaller?.length>1){const previousCallerName=previousCaller[0],previousCallerMethod=previousCaller[1];previousSource=`${previousCallerName}::${previousCallerMethod}]`+"[";}return previousSource}writeLog(level,prefix,caller,message,...params){const callerName=this.getCallerName(caller);const source=this.getPreviousSource()+pc.white(`${this.ownerName}::${callerName}`);let messagePrefix="";if(this.messagePrefixes.length){messagePrefix=`[${this.messagePrefixes.join("][")}]`;}const timestampValue=Date.now();const timeDiff=(timestampValue-Logger.lastLogTime).toString().padStart(4,"0");const timeFormat=Logger.getTimestampFormat();const timestamp=timeFormat?this.formatTime(new Date(timestampValue),timeFormat):"";this.outputEvent(prefix,timeDiff,source,messagePrefix,message,params);const timestampPart=timestamp?`${timestamp} `:"";const output=`${timestampPart}${prefix}[+${timeDiff}ms][${source}]${messagePrefix}: ${message}`;const formatted=this.createBrowserFormat(level,callerName,messagePrefix,message);const metadata={id:`${timestampValue}-${Math.random().toString(16).slice(2)}`,level,namespace:this.ownerName,callerName,message,messagePrefix,payload:params.length===0?undefined:params.length===1?params[0]:params,timestamp:timestampValue,formatted};this.runWithOutputMetadata(metadata,()=>{this.output(output,...params);});Logger.lastLogTime=timestampValue;}createBrowserFormat(level,callerName,messagePrefix,message){const prefixLabel=LEVEL_LABELS[level]||level.toUpperCase();const prefixPart=messagePrefix?`${messagePrefix} `:"";return {format:`%c(${prefixLabel})-> %c%c${this.ownerName}%c::%c${callerName}%c() ${prefixPart}${message}%c`,styles:[...this.defaultStyle]}}formatTime(date,format){const pad=(num,size=2)=>num.toString().padStart(size,"0");const tokens={"YYYY":date.getFullYear().toString(),"Y":date.getFullYear().toString(),"M":pad(date.getMonth()+1),"D":pad(date.getDate()),"HH":pad(date.getHours()),"hh":pad(date.getHours()),"mm":pad(date.getMinutes()),"ss":pad(date.getSeconds()),"SSS":pad(date.getMilliseconds(),3),"S":pad(date.getMilliseconds(),3)};return format.replace(/YYYY|HH|hh|mm|ss|SSS|Y|M|D|S|h|m|s/g,token=>tokens[token]??token)}}
|
|
107
107
|
|
|
108
|
-
const isError=value=>value instanceof Error;const isSerializableObject=value=>{if(value===null){return false}if(Array.isArray(value)){return true}return typeof value==="object"&&!isError(value)};const formatPrimitive=value=>{if(typeof value==="symbol"){return value.toString()}if(typeof value==="bigint"){return value.toString()}return value};const buildErrorMetadata=error=>{const typed=error;return {name:error.name,message:error.message,stack:error.stack,cause:typed.cause}};class
|
|
108
|
+
const isError=value=>value instanceof Error;const isSerializableObject=value=>{if(value===null){return false}if(Array.isArray(value)){return true}return typeof value==="object"&&!isError(value)};const formatPrimitive=value=>{if(typeof value==="symbol"){return value.toString()}if(typeof value==="bigint"){return value.toString()}return value};const buildErrorMetadata=error=>{const typed=error;return {name:error.name,message:error.message,stack:error.stack,cause:typed.cause}};class ZenFluxLogger extends Logger{prepareLog(caller,message,params){this.startsEmpty(caller);this.startsWith(caller,{message});if(params.length===0){return}const dropEntries={};const dropPayload={};params.forEach((param,index)=>{const key=`arg_${index}`;if(isError(param)){dropEntries[key]=param.message;dropPayload[key]=buildErrorMetadata(param);return}if(isSerializableObject(param)){this.dump(caller,{[key]:param});return}this.startsWith(caller,{[key]:formatPrimitive(param)});});if(Object.keys(dropEntries).length>0){this.drop(caller,dropEntries,dropPayload);}}log(caller,message,...params){this.prepareLog(caller,message,params);super.log(caller,message,...params);}info(caller,message,...params){this.prepareLog(caller,message,params);super.info(caller,message,...params);}debug(caller,message,...params){this.prepareLog(caller,message,params);super.debug(caller,message,...params);}warn(caller,message,...params){this.prepareLog(caller,message,params);super.warn(caller,message,...params);}error(caller,message,...params){this.prepareLog(caller,message,params);super.error(caller,message,...params);}admin(caller,message,...params){this.prepareLog(caller,message,params);super.admin(caller,message,...params);}}const loggerCache=new Map;const resolveOwnerName=owner=>{if(typeof owner==="string"){return owner}if(owner&&typeof owner.getName==="function"){return owner.getName()}return "UnknownOwner"};const createLogger=(owner,options)=>{const ownerName=resolveOwnerName(owner);const cached=loggerCache.get(ownerName);if(cached){return cached}const logger=new ZenFluxLogger(owner,options);loggerCache.set(ownerName,logger);return logger};
|
|
109
109
|
|
|
110
110
|
class InitializeBase extends ObjectBase{logger;constructor(shouldInitialize=true){super();this.logger=new Logger(this);if(this.initialize&&shouldInitialize){this.initialize();}}debounce(func,delay){let timeoutId;return (...args)=>{clearTimeout(timeoutId);timeoutId=setTimeout(()=>{func.apply(this,args);},delay);}}}
|
|
111
111
|
|
|
@@ -166,7 +166,7 @@ createLogger: createLogger
|
|
|
166
166
|
|
|
167
167
|
var _package = {
|
|
168
168
|
"name": "@zenflux/core",
|
|
169
|
-
"version": "0.1.
|
|
169
|
+
"version": "0.1.25",
|
|
170
170
|
"types": "dist/zenflux-core.d.ts",
|
|
171
171
|
"type": "module",
|
|
172
172
|
"files": [
|
|
@@ -214,7 +214,7 @@ var _package = {
|
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
const name = "@zenflux/core";
|
|
217
|
-
const version = "0.1.
|
|
217
|
+
const version = "0.1.25";
|
|
218
218
|
const types = "dist/zenflux-core.d.ts";
|
|
219
219
|
const type = "module";
|
|
220
220
|
const files = ["dist","types"];
|
package/dist/zenflux-core.d.ts
CHANGED
|
@@ -203,7 +203,7 @@ declare class Controllers extends ObjectBase {
|
|
|
203
203
|
|
|
204
204
|
declare let controllers: Controllers;
|
|
205
205
|
|
|
206
|
-
declare const createLogger: (owner: string | object, options?: LoggerOptions_2) =>
|
|
206
|
+
declare const createLogger: (owner: string | object, options?: LoggerOptions_2) => ZenFluxLogger;
|
|
207
207
|
|
|
208
208
|
declare function destroy(): void;
|
|
209
209
|
|
|
@@ -260,16 +260,6 @@ declare class EventBus extends ObjectBase {
|
|
|
260
260
|
private ensureFunction;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
declare class EyeNoteLogger extends Logger {
|
|
264
|
-
private prepareLog;
|
|
265
|
-
log(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
266
|
-
info(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
267
|
-
debug(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
268
|
-
warn(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
269
|
-
error(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
270
|
-
admin(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
263
|
declare class ForceMethodImplementation extends Error {
|
|
274
264
|
constructor(context: ObjectBase | typeof ObjectBase | string, methodName: string);
|
|
275
265
|
}
|
|
@@ -696,4 +686,14 @@ declare namespace ZenCore {
|
|
|
696
686
|
}
|
|
697
687
|
export default ZenCore;
|
|
698
688
|
|
|
689
|
+
declare class ZenFluxLogger extends Logger {
|
|
690
|
+
private prepareLog;
|
|
691
|
+
log(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
692
|
+
info(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
693
|
+
debug(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
694
|
+
warn(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
695
|
+
error(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
696
|
+
admin(caller: TCaller, message: string, ...params: unknown[]): void;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
699
|
export { }
|
package/dist/zenflux-core.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bundled with love using the help of @zenflux/cli toolkit v0.1.43
|
|
3
|
-
* Bundle name: @zenflux/core fileName: 'zenflux-core', built at
|
|
3
|
+
* Bundle name: @zenflux/core fileName: 'zenflux-core', built at Tue Feb 03 2026 11:53:40 GMT+0200 (Israel Standard Time)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import * as util from 'util';
|
|
@@ -81,7 +81,7 @@ let SimpleEventEmitter=class SimpleEventEmitter{listeners=new Map;on(event,callb
|
|
|
81
81
|
|
|
82
82
|
const DEFAULT_LOG_PREFIX=pc.white("⚪ - [LOG]"),DEFAULT_INFO_PREFIX=pc.blue("🔵 - [INFO]"),DEFAULT_DEBUG_PREFIX=pc.gray("🟤 - [DEBUG]"),DEFAULT_WARN_PREFIX=pc.yellow("🟡 - [WARN]"),DEFAULT_ERROR_PREFIX=pc.red("🔴 - [ERROR]"),DEFAULT_ADMIN_PREFIX=pc.bold("🟣 - [ADMIN]");const LEVEL_LABELS={log:"LOG",info:"INFO",debug:"DEBUG",warn:"WARN",error:"ERROR",admin:"ADMIN"};const registeredNames={};class Logger extends LoggerBrowserInfra{static lastLogTime=Date.now();static timestampFormat=getLoggerTimeFormat();ownerName;messagePrefixes=[];config={};static setTimestampFormat(format){Logger.timestampFormat=(format||"").trim();}static getTimestampFormat(){return Logger.timestampFormat}static getName(){return "ZenFlux/Core/Modules/Logger"}static getLogLevelString(){return getLoggerLogLevelString()}static getLogLevel(){return getLoggerLogLevel()}static attachOutputListener(listener){return LoggerBrowserInfra.attachOutputSubscriber(listener)}static isDebugEnabled(){return isLoggerDebugEnabled()}constructor(owner,options){const{repeatedly=false,skipEventBusHook}=options||{};super(owner,{repeatedly});this.config={skipEventBusHook};this.ownerName=Logger.resolveOwnerName(owner);if(registeredNames[this.ownerName]){throw new Error(`Logger for '${this.ownerName}' already exists`)}registeredNames[this.ownerName]=true;if(isLoggerDisabled()){this.disableLoggers();return}if(isLoggerPreviousSourceDisabled()){this.getPreviousSource=()=>"";}switch(getLoggerLogLevel()){case 0:this.error=()=>{};case 1:this.warn=()=>{};case 2:this.admin=()=>{};case 3:this.info=()=>{};case 4:this.log=()=>{};case 5:this.debug=()=>{};}if(!this.config.skipEventBusHook){EventBus.$.registerMultiInstances(this,[this.outputEvent]);}}addMessagePrefix(prefix){this.messagePrefixes.push(prefix);}log(caller,message,...params){this.writeLog("log",DEFAULT_LOG_PREFIX,caller,message,...params);}info(caller,message,...params){this.writeLog("info",DEFAULT_INFO_PREFIX,caller,message,...params);}debug(caller,message,...params){this.writeLog("debug",DEFAULT_DEBUG_PREFIX,caller,message,...params);}warn(caller,message,...params){this.writeLog("warn",DEFAULT_WARN_PREFIX,caller,message,...params);}error(caller,message,...params){this.writeLog("error",DEFAULT_ERROR_PREFIX,caller,message,...params);}admin(caller,message,...params){this.writeLog("admin",DEFAULT_ADMIN_PREFIX,caller,message,...params);}startsEmpty(caller){this.printFunctionNotify("▶",caller,"");}startsWith(caller,params){this.printObjectEfficient("▶",caller,params);}dump(caller,params={},notice=""){for(const key in params){if(typeof params[key]==="object"){params[key]=JSON.stringify(LoggerBrowserInfra.useObjectMapper(params[key]),reduceCircularReferences());}this.printInLineElement("dp",caller,key,params[key],notice);}}drop(caller,according,data){for(const key in according){this.printInLineElement("dr",caller,key,according[key],"corresponding");}this.output(data);}throw(caller,output,name="null",params={}){this.printFunctionNotify("tw",caller,output);if(params){this.printInNextLineObject("tw",caller,name,params);}throw new Error().stack}beep(){console.log("\x07");}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}outputEvent(_prefix,_timeDiff,_source,_messagePrefix,_message,_params){}static resolveOwnerName(owner){if(typeof owner==="string"){return owner}if(owner instanceof ObjectBase){return owner.getName()}if(owner&&typeof owner.getName==="function"){return owner.getName()}return "UnknownOwner"}disableLoggers(){this.error=()=>{};this.warn=()=>{};this.admin=()=>{};this.info=()=>{};this.log=()=>{};this.debug=()=>{};}getStackTrace(){const stackTrace=(new Error().stack||"").split("\n");const stackLines=stackTrace.slice(1);const stackRegex=/ at (.+?) \((.+?)\)/;const result=[];for(const line of stackLines){const match=line.match(stackRegex);if(match){const[,context,file]=match;const parsedLine={context,file};if(line.startsWith("new")){parsedLine.isNew=true;parsedLine.object=context.split(" ")[1];}else if(context!=="Object.<anonymous>"){parsedLine.object=context;}result.push(parsedLine);}}return result}getPreviousSource(){const stack=this.getStackTrace().filter(line=>line.file.includes("/src/")).filter(line=>!line.file.includes("logger.ts")).filter(line=>!line.file.includes("debugger.ts")).filter(line=>!line.file.includes("/node_modules/"));let previousSource="";const previousCaller=stack[1]?.object?.split(".");if(previousCaller?.length>1){const previousCallerName=previousCaller[0],previousCallerMethod=previousCaller[1];previousSource=`${previousCallerName}::${previousCallerMethod}]`+"[";}return previousSource}writeLog(level,prefix,caller,message,...params){const callerName=this.getCallerName(caller);const source=this.getPreviousSource()+pc.white(`${this.ownerName}::${callerName}`);let messagePrefix="";if(this.messagePrefixes.length){messagePrefix=`[${this.messagePrefixes.join("][")}]`;}const timestampValue=Date.now();const timeDiff=(timestampValue-Logger.lastLogTime).toString().padStart(4,"0");const timeFormat=Logger.getTimestampFormat();const timestamp=timeFormat?this.formatTime(new Date(timestampValue),timeFormat):"";this.outputEvent(prefix,timeDiff,source,messagePrefix,message,params);const timestampPart=timestamp?`${timestamp} `:"";const output=`${timestampPart}${prefix}[+${timeDiff}ms][${source}]${messagePrefix}: ${message}`;const formatted=this.createBrowserFormat(level,callerName,messagePrefix,message);const metadata={id:`${timestampValue}-${Math.random().toString(16).slice(2)}`,level,namespace:this.ownerName,callerName,message,messagePrefix,payload:params.length===0?undefined:params.length===1?params[0]:params,timestamp:timestampValue,formatted};this.runWithOutputMetadata(metadata,()=>{this.output(output,...params);});Logger.lastLogTime=timestampValue;}createBrowserFormat(level,callerName,messagePrefix,message){const prefixLabel=LEVEL_LABELS[level]||level.toUpperCase();const prefixPart=messagePrefix?`${messagePrefix} `:"";return {format:`%c(${prefixLabel})-> %c%c${this.ownerName}%c::%c${callerName}%c() ${prefixPart}${message}%c`,styles:[...this.defaultStyle]}}formatTime(date,format){const pad=(num,size=2)=>num.toString().padStart(size,"0");const tokens={"YYYY":date.getFullYear().toString(),"Y":date.getFullYear().toString(),"M":pad(date.getMonth()+1),"D":pad(date.getDate()),"HH":pad(date.getHours()),"hh":pad(date.getHours()),"mm":pad(date.getMinutes()),"ss":pad(date.getSeconds()),"SSS":pad(date.getMilliseconds(),3),"S":pad(date.getMilliseconds(),3)};return format.replace(/YYYY|HH|hh|mm|ss|SSS|Y|M|D|S|h|m|s/g,token=>tokens[token]??token)}}
|
|
83
83
|
|
|
84
|
-
const isError=value=>value instanceof Error;const isSerializableObject=value=>{if(value===null){return false}if(Array.isArray(value)){return true}return typeof value==="object"&&!isError(value)};const formatPrimitive=value=>{if(typeof value==="symbol"){return value.toString()}if(typeof value==="bigint"){return value.toString()}return value};const buildErrorMetadata=error=>{const typed=error;return {name:error.name,message:error.message,stack:error.stack,cause:typed.cause}};class
|
|
84
|
+
const isError=value=>value instanceof Error;const isSerializableObject=value=>{if(value===null){return false}if(Array.isArray(value)){return true}return typeof value==="object"&&!isError(value)};const formatPrimitive=value=>{if(typeof value==="symbol"){return value.toString()}if(typeof value==="bigint"){return value.toString()}return value};const buildErrorMetadata=error=>{const typed=error;return {name:error.name,message:error.message,stack:error.stack,cause:typed.cause}};class ZenFluxLogger extends Logger{prepareLog(caller,message,params){this.startsEmpty(caller);this.startsWith(caller,{message});if(params.length===0){return}const dropEntries={};const dropPayload={};params.forEach((param,index)=>{const key=`arg_${index}`;if(isError(param)){dropEntries[key]=param.message;dropPayload[key]=buildErrorMetadata(param);return}if(isSerializableObject(param)){this.dump(caller,{[key]:param});return}this.startsWith(caller,{[key]:formatPrimitive(param)});});if(Object.keys(dropEntries).length>0){this.drop(caller,dropEntries,dropPayload);}}log(caller,message,...params){this.prepareLog(caller,message,params);super.log(caller,message,...params);}info(caller,message,...params){this.prepareLog(caller,message,params);super.info(caller,message,...params);}debug(caller,message,...params){this.prepareLog(caller,message,params);super.debug(caller,message,...params);}warn(caller,message,...params){this.prepareLog(caller,message,params);super.warn(caller,message,...params);}error(caller,message,...params){this.prepareLog(caller,message,params);super.error(caller,message,...params);}admin(caller,message,...params){this.prepareLog(caller,message,params);super.admin(caller,message,...params);}}const loggerCache=new Map;const resolveOwnerName=owner=>{if(typeof owner==="string"){return owner}if(owner&&typeof owner.getName==="function"){return owner.getName()}return "UnknownOwner"};const createLogger=(owner,options)=>{const ownerName=resolveOwnerName(owner);const cached=loggerCache.get(ownerName);if(cached){return cached}const logger=new ZenFluxLogger(owner,options);loggerCache.set(ownerName,logger);return logger};
|
|
85
85
|
|
|
86
86
|
class InitializeBase extends ObjectBase{logger;constructor(shouldInitialize=true){super();this.logger=new Logger(this);if(this.initialize&&shouldInitialize){this.initialize();}}debounce(func,delay){let timeoutId;return (...args)=>{clearTimeout(timeoutId);timeoutId=setTimeout(()=>{func.apply(this,args);},delay);}}}
|
|
87
87
|
|
|
@@ -142,7 +142,7 @@ createLogger: createLogger
|
|
|
142
142
|
|
|
143
143
|
var _package = {
|
|
144
144
|
"name": "@zenflux/core",
|
|
145
|
-
"version": "0.1.
|
|
145
|
+
"version": "0.1.25",
|
|
146
146
|
"types": "dist/zenflux-core.d.ts",
|
|
147
147
|
"type": "module",
|
|
148
148
|
"files": [
|
|
@@ -190,7 +190,7 @@ var _package = {
|
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
192
|
const name = "@zenflux/core";
|
|
193
|
-
const version = "0.1.
|
|
193
|
+
const version = "0.1.25";
|
|
194
194
|
const types = "dist/zenflux-core.d.ts";
|
|
195
195
|
const type = "module";
|
|
196
196
|
const files = ["dist","types"];
|