@eko-ai/eko 1.2.0 → 1.2.2

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.
@@ -1,3 +1,631 @@
1
+ import { hostname } from 'os';
2
+ import { normalize } from 'path';
3
+ import { types, formatWithOptions } from 'util';
4
+
5
+ const prettyLogStyles = {
6
+ reset: [0, 0],
7
+ bold: [1, 22],
8
+ dim: [2, 22],
9
+ italic: [3, 23],
10
+ underline: [4, 24],
11
+ overline: [53, 55],
12
+ inverse: [7, 27],
13
+ hidden: [8, 28],
14
+ strikethrough: [9, 29],
15
+ black: [30, 39],
16
+ red: [31, 39],
17
+ green: [32, 39],
18
+ yellow: [33, 39],
19
+ blue: [34, 39],
20
+ magenta: [35, 39],
21
+ cyan: [36, 39],
22
+ white: [37, 39],
23
+ blackBright: [90, 39],
24
+ redBright: [91, 39],
25
+ greenBright: [92, 39],
26
+ yellowBright: [93, 39],
27
+ blueBright: [94, 39],
28
+ magentaBright: [95, 39],
29
+ cyanBright: [96, 39],
30
+ whiteBright: [97, 39],
31
+ bgBlack: [40, 49],
32
+ bgRed: [41, 49],
33
+ bgGreen: [42, 49],
34
+ bgYellow: [43, 49],
35
+ bgBlue: [44, 49],
36
+ bgMagenta: [45, 49],
37
+ bgCyan: [46, 49],
38
+ bgWhite: [47, 49],
39
+ bgBlackBright: [100, 49],
40
+ bgRedBright: [101, 49],
41
+ bgGreenBright: [102, 49],
42
+ bgYellowBright: [103, 49],
43
+ bgBlueBright: [104, 49],
44
+ bgMagentaBright: [105, 49],
45
+ bgCyanBright: [106, 49],
46
+ bgWhiteBright: [107, 49],
47
+ };
48
+
49
+ function formatTemplate(settings, template, values, hideUnsetPlaceholder = false) {
50
+ const templateString = String(template);
51
+ const ansiColorWrap = (placeholderValue, code) => `\u001b[${code[0]}m${placeholderValue}\u001b[${code[1]}m`;
52
+ const styleWrap = (value, style) => {
53
+ if (style != null && typeof style === "string") {
54
+ return ansiColorWrap(value, prettyLogStyles[style]);
55
+ }
56
+ else if (style != null && Array.isArray(style)) {
57
+ return style.reduce((prevValue, thisStyle) => styleWrap(prevValue, thisStyle), value);
58
+ }
59
+ else {
60
+ if (style != null && style[value.trim()] != null) {
61
+ return styleWrap(value, style[value.trim()]);
62
+ }
63
+ else if (style != null && style["*"] != null) {
64
+ return styleWrap(value, style["*"]);
65
+ }
66
+ else {
67
+ return value;
68
+ }
69
+ }
70
+ };
71
+ const defaultStyle = null;
72
+ return templateString.replace(/{{(.+?)}}/g, (_, placeholder) => {
73
+ const value = values[placeholder] != null ? String(values[placeholder]) : hideUnsetPlaceholder ? "" : _;
74
+ return settings.stylePrettyLogs
75
+ ? styleWrap(value, settings?.prettyLogStyles?.[placeholder] ?? defaultStyle) + ansiColorWrap("", prettyLogStyles.reset)
76
+ : value;
77
+ });
78
+ }
79
+
80
+ function formatNumberAddZeros(value, digits = 2, addNumber = 0) {
81
+ if (value != null && isNaN(value)) {
82
+ return "";
83
+ }
84
+ value = value != null ? value + addNumber : value;
85
+ return digits === 2
86
+ ? value == null
87
+ ? "--"
88
+ : value < 10
89
+ ? "0" + value
90
+ : value.toString()
91
+ : value == null
92
+ ? "---"
93
+ : value < 10
94
+ ? "00" + value
95
+ : value < 100
96
+ ? "0" + value
97
+ : value.toString();
98
+ }
99
+
100
+ function urlToObject(url) {
101
+ return {
102
+ href: url.href,
103
+ protocol: url.protocol,
104
+ username: url.username,
105
+ password: url.password,
106
+ host: url.host,
107
+ hostname: url.hostname,
108
+ port: url.port,
109
+ pathname: url.pathname,
110
+ search: url.search,
111
+ searchParams: [...url.searchParams].map(([key, value]) => ({ key, value })),
112
+ hash: url.hash,
113
+ origin: url.origin,
114
+ };
115
+ }
116
+
117
+ var Runtime = {
118
+ getCallerStackFrame,
119
+ getErrorTrace,
120
+ getMeta,
121
+ transportJSON,
122
+ transportFormatted: transportFormatted$1,
123
+ isBuffer,
124
+ isError,
125
+ prettyFormatLogObj,
126
+ prettyFormatErrorObj,
127
+ };
128
+ const meta = {
129
+ runtime: "Nodejs",
130
+ runtimeVersion: process?.version,
131
+ hostname: hostname ? hostname() : undefined,
132
+ };
133
+ function getMeta(logLevelId, logLevelName, stackDepthLevel, hideLogPositionForPerformance, name, parentNames) {
134
+ return Object.assign({}, meta, {
135
+ name,
136
+ parentNames,
137
+ date: new Date(),
138
+ logLevelId,
139
+ logLevelName,
140
+ path: !hideLogPositionForPerformance ? getCallerStackFrame(stackDepthLevel) : undefined,
141
+ });
142
+ }
143
+ function getCallerStackFrame(stackDepthLevel, error = Error()) {
144
+ return stackLineToStackFrame(error?.stack?.split("\n")?.filter((thisLine) => thisLine.includes(" at "))?.[stackDepthLevel]);
145
+ }
146
+ function getErrorTrace(error) {
147
+ return error?.stack?.split("\n")?.reduce((result, line) => {
148
+ if (line.includes(" at ")) {
149
+ result.push(stackLineToStackFrame(line));
150
+ }
151
+ return result;
152
+ }, []);
153
+ }
154
+ function stackLineToStackFrame(line) {
155
+ const pathResult = {
156
+ fullFilePath: undefined,
157
+ fileName: undefined,
158
+ fileNameWithLine: undefined,
159
+ fileColumn: undefined,
160
+ fileLine: undefined,
161
+ filePath: undefined,
162
+ filePathWithLine: undefined,
163
+ method: undefined,
164
+ };
165
+ if (line != null && line.includes(" at ")) {
166
+ line = line.replace(/^\s+at\s+/gm, "");
167
+ const errorStackLine = line.split(" (");
168
+ const fullFilePath = line?.slice(-1) === ")" ? line?.match(/\(([^)]+)\)/)?.[1] : line;
169
+ const pathArray = fullFilePath?.includes(":") ? fullFilePath?.replace("file://", "")?.replace(process.cwd(), "")?.split(":") : undefined;
170
+ const fileColumn = pathArray?.pop();
171
+ const fileLine = pathArray?.pop();
172
+ const filePath = pathArray?.pop();
173
+ const filePathWithLine = normalize(`${filePath}:${fileLine}`);
174
+ const fileName = filePath?.split("/")?.pop();
175
+ const fileNameWithLine = `${fileName}:${fileLine}`;
176
+ if (filePath != null && filePath.length > 0) {
177
+ pathResult.fullFilePath = fullFilePath;
178
+ pathResult.fileName = fileName;
179
+ pathResult.fileNameWithLine = fileNameWithLine;
180
+ pathResult.fileColumn = fileColumn;
181
+ pathResult.fileLine = fileLine;
182
+ pathResult.filePath = filePath;
183
+ pathResult.filePathWithLine = filePathWithLine;
184
+ pathResult.method = errorStackLine?.[1] != null ? errorStackLine?.[0] : undefined;
185
+ }
186
+ }
187
+ return pathResult;
188
+ }
189
+ function isError(e) {
190
+ return types?.isNativeError != null ? types.isNativeError(e) : e instanceof Error;
191
+ }
192
+ function prettyFormatLogObj(maskedArgs, settings) {
193
+ return maskedArgs.reduce((result, arg) => {
194
+ isError(arg) ? result.errors.push(prettyFormatErrorObj(arg, settings)) : result.args.push(arg);
195
+ return result;
196
+ }, { args: [], errors: [] });
197
+ }
198
+ function prettyFormatErrorObj(error, settings) {
199
+ const errorStackStr = getErrorTrace(error).map((stackFrame) => {
200
+ return formatTemplate(settings, settings.prettyErrorStackTemplate, { ...stackFrame }, true);
201
+ });
202
+ const placeholderValuesError = {
203
+ errorName: ` ${error.name} `,
204
+ errorMessage: Object.getOwnPropertyNames(error)
205
+ .reduce((result, key) => {
206
+ if (key !== "stack") {
207
+ result.push(error[key]);
208
+ }
209
+ return result;
210
+ }, [])
211
+ .join(", "),
212
+ errorStack: errorStackStr.join("\n"),
213
+ };
214
+ return formatTemplate(settings, settings.prettyErrorTemplate, placeholderValuesError);
215
+ }
216
+ function transportFormatted$1(logMetaMarkup, logArgs, logErrors, settings) {
217
+ const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
218
+ settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
219
+ console.log(logMetaMarkup + formatWithOptions(settings.prettyInspectOptions, ...logArgs) + logErrorsStr);
220
+ }
221
+ function transportJSON(json) {
222
+ console.log(jsonStringifyRecursive(json));
223
+ function jsonStringifyRecursive(obj) {
224
+ const cache = new Set();
225
+ return JSON.stringify(obj, (key, value) => {
226
+ if (typeof value === "object" && value !== null) {
227
+ if (cache.has(value)) {
228
+ return "[Circular]";
229
+ }
230
+ cache.add(value);
231
+ }
232
+ if (typeof value === "bigint") {
233
+ return `${value}`;
234
+ }
235
+ if (typeof value === "undefined") {
236
+ return "[undefined]";
237
+ }
238
+ return value;
239
+ });
240
+ }
241
+ }
242
+ function isBuffer(arg) {
243
+ return Buffer.isBuffer(arg);
244
+ }
245
+
246
+ class BaseLogger {
247
+ constructor(settings, logObj, stackDepthLevel = 4) {
248
+ this.logObj = logObj;
249
+ this.stackDepthLevel = stackDepthLevel;
250
+ this.runtime = Runtime;
251
+ this.settings = {
252
+ type: settings?.type ?? "pretty",
253
+ name: settings?.name,
254
+ parentNames: settings?.parentNames,
255
+ minLevel: settings?.minLevel ?? 0,
256
+ argumentsArrayName: settings?.argumentsArrayName,
257
+ hideLogPositionForProduction: settings?.hideLogPositionForProduction ?? false,
258
+ prettyLogTemplate: settings?.prettyLogTemplate ??
259
+ "{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t{{filePathWithLine}}{{nameWithDelimiterPrefix}}\t",
260
+ prettyErrorTemplate: settings?.prettyErrorTemplate ?? "\n{{errorName}} {{errorMessage}}\nerror stack:\n{{errorStack}}",
261
+ prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? " • {{fileName}}\t{{method}}\n\t{{filePathWithLine}}",
262
+ prettyErrorParentNamesSeparator: settings?.prettyErrorParentNamesSeparator ?? ":",
263
+ prettyErrorLoggerNameDelimiter: settings?.prettyErrorLoggerNameDelimiter ?? "\t",
264
+ stylePrettyLogs: settings?.stylePrettyLogs ?? true,
265
+ prettyLogTimeZone: settings?.prettyLogTimeZone ?? "UTC",
266
+ prettyLogStyles: settings?.prettyLogStyles ?? {
267
+ logLevelName: {
268
+ "*": ["bold", "black", "bgWhiteBright", "dim"],
269
+ SILLY: ["bold", "white"],
270
+ TRACE: ["bold", "whiteBright"],
271
+ DEBUG: ["bold", "green"],
272
+ INFO: ["bold", "blue"],
273
+ WARN: ["bold", "yellow"],
274
+ ERROR: ["bold", "red"],
275
+ FATAL: ["bold", "redBright"],
276
+ },
277
+ dateIsoStr: "white",
278
+ filePathWithLine: "white",
279
+ name: ["white", "bold"],
280
+ nameWithDelimiterPrefix: ["white", "bold"],
281
+ nameWithDelimiterSuffix: ["white", "bold"],
282
+ errorName: ["bold", "bgRedBright", "whiteBright"],
283
+ fileName: ["yellow"],
284
+ fileNameWithLine: "white",
285
+ },
286
+ prettyInspectOptions: settings?.prettyInspectOptions ?? {
287
+ colors: true,
288
+ compact: false,
289
+ depth: Infinity,
290
+ },
291
+ metaProperty: settings?.metaProperty ?? "_meta",
292
+ maskPlaceholder: settings?.maskPlaceholder ?? "[***]",
293
+ maskValuesOfKeys: settings?.maskValuesOfKeys ?? ["password"],
294
+ maskValuesOfKeysCaseInsensitive: settings?.maskValuesOfKeysCaseInsensitive ?? false,
295
+ maskValuesRegEx: settings?.maskValuesRegEx,
296
+ prefix: [...(settings?.prefix ?? [])],
297
+ attachedTransports: [...(settings?.attachedTransports ?? [])],
298
+ overwrite: {
299
+ mask: settings?.overwrite?.mask,
300
+ toLogObj: settings?.overwrite?.toLogObj,
301
+ addMeta: settings?.overwrite?.addMeta,
302
+ addPlaceholders: settings?.overwrite?.addPlaceholders,
303
+ formatMeta: settings?.overwrite?.formatMeta,
304
+ formatLogObj: settings?.overwrite?.formatLogObj,
305
+ transportFormatted: settings?.overwrite?.transportFormatted,
306
+ transportJSON: settings?.overwrite?.transportJSON,
307
+ },
308
+ };
309
+ }
310
+ log(logLevelId, logLevelName, ...args) {
311
+ if (logLevelId < this.settings.minLevel) {
312
+ return;
313
+ }
314
+ const logArgs = [...this.settings.prefix, ...args];
315
+ const maskedArgs = this.settings.overwrite?.mask != null
316
+ ? this.settings.overwrite?.mask(logArgs)
317
+ : this.settings.maskValuesOfKeys != null && this.settings.maskValuesOfKeys.length > 0
318
+ ? this._mask(logArgs)
319
+ : logArgs;
320
+ const thisLogObj = this.logObj != null ? this._recursiveCloneAndExecuteFunctions(this.logObj) : undefined;
321
+ const logObj = this.settings.overwrite?.toLogObj != null ? this.settings.overwrite?.toLogObj(maskedArgs, thisLogObj) : this._toLogObj(maskedArgs, thisLogObj);
322
+ const logObjWithMeta = this.settings.overwrite?.addMeta != null
323
+ ? this.settings.overwrite?.addMeta(logObj, logLevelId, logLevelName)
324
+ : this._addMetaToLogObj(logObj, logLevelId, logLevelName);
325
+ let logMetaMarkup;
326
+ let logArgsAndErrorsMarkup = undefined;
327
+ if (this.settings.overwrite?.formatMeta != null) {
328
+ logMetaMarkup = this.settings.overwrite?.formatMeta(logObjWithMeta?.[this.settings.metaProperty]);
329
+ }
330
+ if (this.settings.overwrite?.formatLogObj != null) {
331
+ logArgsAndErrorsMarkup = this.settings.overwrite?.formatLogObj(maskedArgs, this.settings);
332
+ }
333
+ if (this.settings.type === "pretty") {
334
+ logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
335
+ logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? this.runtime.prettyFormatLogObj(maskedArgs, this.settings);
336
+ }
337
+ if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {
338
+ this.settings.overwrite?.transportFormatted != null
339
+ ? this.settings.overwrite?.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings)
340
+ : this.runtime.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings);
341
+ }
342
+ else {
343
+ this.settings.overwrite?.transportJSON != null
344
+ ? this.settings.overwrite?.transportJSON(logObjWithMeta)
345
+ : this.settings.type !== "hidden"
346
+ ? this.runtime.transportJSON(logObjWithMeta)
347
+ : undefined;
348
+ }
349
+ if (this.settings.attachedTransports != null && this.settings.attachedTransports.length > 0) {
350
+ this.settings.attachedTransports.forEach((transportLogger) => {
351
+ transportLogger(logObjWithMeta);
352
+ });
353
+ }
354
+ return logObjWithMeta;
355
+ }
356
+ attachTransport(transportLogger) {
357
+ this.settings.attachedTransports.push(transportLogger);
358
+ }
359
+ getSubLogger(settings, logObj) {
360
+ const subLoggerSettings = {
361
+ ...this.settings,
362
+ ...settings,
363
+ parentNames: this.settings?.parentNames != null && this.settings?.name != null
364
+ ? [...this.settings.parentNames, this.settings.name]
365
+ : this.settings?.name != null
366
+ ? [this.settings.name]
367
+ : undefined,
368
+ prefix: [...this.settings.prefix, ...(settings?.prefix ?? [])],
369
+ };
370
+ const subLogger = new this.constructor(subLoggerSettings, logObj ?? this.logObj, this.stackDepthLevel);
371
+ return subLogger;
372
+ }
373
+ _mask(args) {
374
+ const maskValuesOfKeys = this.settings.maskValuesOfKeysCaseInsensitive !== true ? this.settings.maskValuesOfKeys : this.settings.maskValuesOfKeys.map((key) => key.toLowerCase());
375
+ return args?.map((arg) => {
376
+ return this._recursiveCloneAndMaskValuesOfKeys(arg, maskValuesOfKeys);
377
+ });
378
+ }
379
+ _recursiveCloneAndMaskValuesOfKeys(source, keys, seen = []) {
380
+ if (seen.includes(source)) {
381
+ return { ...source };
382
+ }
383
+ if (typeof source === "object" && source !== null) {
384
+ seen.push(source);
385
+ }
386
+ if (this.runtime.isError(source) || this.runtime.isBuffer(source)) {
387
+ return source;
388
+ }
389
+ else if (source instanceof Map) {
390
+ return new Map(source);
391
+ }
392
+ else if (source instanceof Set) {
393
+ return new Set(source);
394
+ }
395
+ else if (Array.isArray(source)) {
396
+ return source.map((item) => this._recursiveCloneAndMaskValuesOfKeys(item, keys, seen));
397
+ }
398
+ else if (source instanceof Date) {
399
+ return new Date(source.getTime());
400
+ }
401
+ else if (source instanceof URL) {
402
+ return urlToObject(source);
403
+ }
404
+ else if (source !== null && typeof source === "object") {
405
+ const baseObject = this.runtime.isError(source) ? this._cloneError(source) : Object.create(Object.getPrototypeOf(source));
406
+ return Object.getOwnPropertyNames(source).reduce((o, prop) => {
407
+ o[prop] = keys.includes(this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : prop.toLowerCase())
408
+ ? this.settings.maskPlaceholder
409
+ : (() => {
410
+ try {
411
+ return this._recursiveCloneAndMaskValuesOfKeys(source[prop], keys, seen);
412
+ }
413
+ catch (e) {
414
+ return null;
415
+ }
416
+ })();
417
+ return o;
418
+ }, baseObject);
419
+ }
420
+ else {
421
+ if (typeof source === "string") {
422
+ let modifiedSource = source;
423
+ for (const regEx of this.settings?.maskValuesRegEx || []) {
424
+ modifiedSource = modifiedSource.replace(regEx, this.settings?.maskPlaceholder || "");
425
+ }
426
+ return modifiedSource;
427
+ }
428
+ return source;
429
+ }
430
+ }
431
+ _recursiveCloneAndExecuteFunctions(source, seen = []) {
432
+ if (this.isObjectOrArray(source) && seen.includes(source)) {
433
+ return this.shallowCopy(source);
434
+ }
435
+ if (this.isObjectOrArray(source)) {
436
+ seen.push(source);
437
+ }
438
+ if (Array.isArray(source)) {
439
+ return source.map((item) => this._recursiveCloneAndExecuteFunctions(item, seen));
440
+ }
441
+ else if (source instanceof Date) {
442
+ return new Date(source.getTime());
443
+ }
444
+ else if (this.isObject(source)) {
445
+ return Object.getOwnPropertyNames(source).reduce((o, prop) => {
446
+ const descriptor = Object.getOwnPropertyDescriptor(source, prop);
447
+ if (descriptor) {
448
+ Object.defineProperty(o, prop, descriptor);
449
+ const value = source[prop];
450
+ o[prop] = typeof value === "function" ? value() : this._recursiveCloneAndExecuteFunctions(value, seen);
451
+ }
452
+ return o;
453
+ }, Object.create(Object.getPrototypeOf(source)));
454
+ }
455
+ else {
456
+ return source;
457
+ }
458
+ }
459
+ isObjectOrArray(value) {
460
+ return typeof value === "object" && value !== null;
461
+ }
462
+ isObject(value) {
463
+ return typeof value === "object" && !Array.isArray(value) && value !== null;
464
+ }
465
+ shallowCopy(source) {
466
+ if (Array.isArray(source)) {
467
+ return [...source];
468
+ }
469
+ else {
470
+ return { ...source };
471
+ }
472
+ }
473
+ _toLogObj(args, clonedLogObj = {}) {
474
+ args = args?.map((arg) => (this.runtime.isError(arg) ? this._toErrorObject(arg) : arg));
475
+ if (this.settings.argumentsArrayName == null) {
476
+ if (args.length === 1 && !Array.isArray(args[0]) && this.runtime.isBuffer(args[0]) !== true && !(args[0] instanceof Date)) {
477
+ clonedLogObj = typeof args[0] === "object" && args[0] != null ? { ...args[0], ...clonedLogObj } : { 0: args[0], ...clonedLogObj };
478
+ }
479
+ else {
480
+ clonedLogObj = { ...clonedLogObj, ...args };
481
+ }
482
+ }
483
+ else {
484
+ clonedLogObj = {
485
+ ...clonedLogObj,
486
+ [this.settings.argumentsArrayName]: args,
487
+ };
488
+ }
489
+ return clonedLogObj;
490
+ }
491
+ _cloneError(error) {
492
+ const cloned = new error.constructor();
493
+ Object.getOwnPropertyNames(error).forEach((key) => {
494
+ cloned[key] = error[key];
495
+ });
496
+ return cloned;
497
+ }
498
+ _toErrorObject(error) {
499
+ return {
500
+ nativeError: error,
501
+ name: error.name ?? "Error",
502
+ message: error.message,
503
+ stack: this.runtime.getErrorTrace(error),
504
+ };
505
+ }
506
+ _addMetaToLogObj(logObj, logLevelId, logLevelName) {
507
+ return {
508
+ ...logObj,
509
+ [this.settings.metaProperty]: this.runtime.getMeta(logLevelId, logLevelName, this.stackDepthLevel, this.settings.hideLogPositionForProduction, this.settings.name, this.settings.parentNames),
510
+ };
511
+ }
512
+ _prettyFormatLogObjMeta(logObjMeta) {
513
+ if (logObjMeta == null) {
514
+ return "";
515
+ }
516
+ let template = this.settings.prettyLogTemplate;
517
+ const placeholderValues = {};
518
+ if (template.includes("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}")) {
519
+ template = template.replace("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}", "{{dateIsoStr}}");
520
+ }
521
+ else {
522
+ if (this.settings.prettyLogTimeZone === "UTC") {
523
+ placeholderValues["yyyy"] = logObjMeta?.date?.getUTCFullYear() ?? "----";
524
+ placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMonth(), 2, 1);
525
+ placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getUTCDate(), 2);
526
+ placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getUTCHours(), 2);
527
+ placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMinutes(), 2);
528
+ placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getUTCSeconds(), 2);
529
+ placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMilliseconds(), 3);
530
+ }
531
+ else {
532
+ placeholderValues["yyyy"] = logObjMeta?.date?.getFullYear() ?? "----";
533
+ placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getMonth(), 2, 1);
534
+ placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getDate(), 2);
535
+ placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getHours(), 2);
536
+ placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getMinutes(), 2);
537
+ placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getSeconds(), 2);
538
+ placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getMilliseconds(), 3);
539
+ }
540
+ }
541
+ const dateInSettingsTimeZone = this.settings.prettyLogTimeZone === "UTC" ? logObjMeta?.date : new Date(logObjMeta?.date?.getTime() - logObjMeta?.date?.getTimezoneOffset() * 60000);
542
+ placeholderValues["rawIsoStr"] = dateInSettingsTimeZone?.toISOString();
543
+ placeholderValues["dateIsoStr"] = dateInSettingsTimeZone?.toISOString().replace("T", " ").replace("Z", "");
544
+ placeholderValues["logLevelName"] = logObjMeta?.logLevelName;
545
+ placeholderValues["fileNameWithLine"] = logObjMeta?.path?.fileNameWithLine ?? "";
546
+ placeholderValues["filePathWithLine"] = logObjMeta?.path?.filePathWithLine ?? "";
547
+ placeholderValues["fullFilePath"] = logObjMeta?.path?.fullFilePath ?? "";
548
+ let parentNamesString = this.settings.parentNames?.join(this.settings.prettyErrorParentNamesSeparator);
549
+ parentNamesString = parentNamesString != null && logObjMeta?.name != null ? parentNamesString + this.settings.prettyErrorParentNamesSeparator : undefined;
550
+ placeholderValues["name"] = logObjMeta?.name != null || parentNamesString != null ? (parentNamesString ?? "") + logObjMeta?.name ?? "" : "";
551
+ placeholderValues["nameWithDelimiterPrefix"] =
552
+ placeholderValues["name"].length > 0 ? this.settings.prettyErrorLoggerNameDelimiter + placeholderValues["name"] : "";
553
+ placeholderValues["nameWithDelimiterSuffix"] =
554
+ placeholderValues["name"].length > 0 ? placeholderValues["name"] + this.settings.prettyErrorLoggerNameDelimiter : "";
555
+ if (this.settings.overwrite?.addPlaceholders != null) {
556
+ this.settings.overwrite?.addPlaceholders(logObjMeta, placeholderValues);
557
+ }
558
+ return formatTemplate(this.settings, template, placeholderValues);
559
+ }
560
+ }
561
+
562
+ class Logger extends BaseLogger {
563
+ constructor(settings, logObj) {
564
+ const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
565
+ const isBrowserBlinkEngine = isBrowser ? window.chrome !== undefined && window.CSS !== undefined && window.CSS.supports("color", "green") : false;
566
+ const isSafari = isBrowser ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false;
567
+ settings = settings || {};
568
+ settings.stylePrettyLogs = settings.stylePrettyLogs && isBrowser && !isBrowserBlinkEngine ? false : settings.stylePrettyLogs;
569
+ super(settings, logObj, isSafari ? 4 : 5);
570
+ }
571
+ log(logLevelId, logLevelName, ...args) {
572
+ return super.log(logLevelId, logLevelName, ...args);
573
+ }
574
+ silly(...args) {
575
+ return super.log(0, "SILLY", ...args);
576
+ }
577
+ trace(...args) {
578
+ return super.log(1, "TRACE", ...args);
579
+ }
580
+ debug(...args) {
581
+ return super.log(2, "DEBUG", ...args);
582
+ }
583
+ info(...args) {
584
+ return super.log(3, "INFO", ...args);
585
+ }
586
+ warn(...args) {
587
+ return super.log(4, "WARN", ...args);
588
+ }
589
+ error(...args) {
590
+ return super.log(5, "ERROR", ...args);
591
+ }
592
+ fatal(...args) {
593
+ return super.log(6, "FATAL", ...args);
594
+ }
595
+ getSubLogger(settings, logObj) {
596
+ return super.getSubLogger(settings, logObj);
597
+ }
598
+ }
599
+
600
+ function transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
601
+ const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
602
+ settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
603
+ console.log(logMetaMarkup, ...logArgs, logErrorsStr);
604
+ }
605
+ function formatMeta(logObjMeta) {
606
+ if (!logObjMeta) {
607
+ return '';
608
+ }
609
+ const { date, logLevelName } = logObjMeta;
610
+ const year = date.getFullYear();
611
+ const month = String(date.getMonth() + 1).padStart(2, '0');
612
+ const day = String(date.getDate()).padStart(2, '0');
613
+ const hours = String(date.getHours()).padStart(2, '0');
614
+ const minutes = String(date.getMinutes()).padStart(2, '0');
615
+ const seconds = String(date.getSeconds()).padStart(2, '0');
616
+ const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
617
+ const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
618
+ const loggerName = logObjMeta.name;
619
+ return `${formattedDate} ${logLevelName} ${loggerName}`;
620
+ }
621
+ const logger = new Logger({
622
+ name: "ekoLogger",
623
+ overwrite: {
624
+ transportFormatted,
625
+ formatMeta,
626
+ }
627
+ });
628
+
1
629
  if (!window.eko) {
2
630
  window.eko = { lastMouseX: 0, lastMouseY: 0 };
3
631
  }
@@ -25,7 +653,7 @@ if (typeof chrome !== 'undefined') {
25
653
  result = await eko.subListeners[request.event](request.params);
26
654
  }
27
655
  catch (e) {
28
- console.log(e);
656
+ logger.error(e);
29
657
  }
30
658
  }
31
659
  sendResponse(result);
@@ -85,7 +713,7 @@ if (typeof chrome !== 'undefined') {
85
713
  }
86
714
  }
87
715
  catch (e) {
88
- console.log('onMessage error', e);
716
+ logger.error('onMessage error', e);
89
717
  sendResponse(false);
90
718
  }
91
719
  })();
@@ -171,7 +799,7 @@ function type(request) {
171
799
  input.dispatchEvent(event);
172
800
  });
173
801
  }
174
- console.log('type', input, request, result);
802
+ logger.debug('type', input, request, result);
175
803
  return true;
176
804
  }
177
805
  function mouse_move(request) {
@@ -188,7 +816,7 @@ function mouse_move(request) {
188
816
  clientY: y,
189
817
  });
190
818
  let result = document.body.dispatchEvent(event);
191
- console.log('mouse_move', document.body, request, result);
819
+ logger.debug('mouse_move', document.body, request, result);
192
820
  return true;
193
821
  }
194
822
  function simulateMouseEvent(request, eventTypes, button) {
@@ -220,7 +848,7 @@ function simulateMouseEvent(request, eventTypes, button) {
220
848
  button, // 0 left; 2 right
221
849
  });
222
850
  let result = element.dispatchEvent(event);
223
- console.log('simulateMouse', element, { ...request, eventTypes, button }, result);
851
+ logger.debug('simulateMouse', element, { ...request, eventTypes, button }, result);
224
852
  }
225
853
  return true;
226
854
  }
@@ -253,7 +881,7 @@ function scroll_to(request) {
253
881
  behavior: 'smooth',
254
882
  });
255
883
  }
256
- console.log('scroll_to', request);
884
+ logger.debug('scroll_to', request);
257
885
  return true;
258
886
  }
259
887
  function get_dropdown_options(request) {