@ncoderz/log-m8 1.1.0 → 1.2.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/README.md +3 -3
- package/dist/browser/log-m8.global.js +1 -1
- package/dist/browser/log-m8.global.js.map +1 -1
- package/dist/index.cjs +53 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +53 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -144,6 +144,7 @@ var import_fs = require("fs");
|
|
|
144
144
|
|
|
145
145
|
// src/LogM8Utils.ts
|
|
146
146
|
var TIMESTAMP_TOKEN_REGEX = /(yyyy|SSS|hh|mm|ss|SS|zz|z|yy|MM|dd|A|a|h|S)/g;
|
|
147
|
+
var REGEX_MATCHER = /^\/(.+)\/([dgimsuvy]*)$/;
|
|
147
148
|
var EXCLUDED_ERROR_KEYS = /* @__PURE__ */ new Set(["name", "message", "stack", "cause"]);
|
|
148
149
|
var COMMON_NON_ENUMERABLE_PROPS = ["code", "errno", "syscall", "path"];
|
|
149
150
|
var LogM8Utils = class _LogM8Utils {
|
|
@@ -539,6 +540,31 @@ var LogM8Utils = class _LogM8Utils {
|
|
|
539
540
|
};
|
|
540
541
|
return serializeErrorInternal(error, /* @__PURE__ */ new WeakSet());
|
|
541
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Take a regex in the format /regex/flags and parse it into a RegExp object
|
|
545
|
+
*
|
|
546
|
+
* @param regex regex in the format /regex/flags
|
|
547
|
+
* @param extraFlags additional flags to apply to the regex
|
|
548
|
+
* @returns RegExp object or undefined if the regex is invalid
|
|
549
|
+
*/
|
|
550
|
+
static parseRegexFromString(regex, extraFlags) {
|
|
551
|
+
try {
|
|
552
|
+
const match = regex.match(REGEX_MATCHER);
|
|
553
|
+
if (match == null) return void 0;
|
|
554
|
+
const [, pattern, flags] = match;
|
|
555
|
+
let finalFlags = flags;
|
|
556
|
+
if (Array.isArray(extraFlags)) {
|
|
557
|
+
for (const flag of extraFlags) {
|
|
558
|
+
if (!flags.includes(flag)) {
|
|
559
|
+
finalFlags += flag;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return new RegExp(pattern, finalFlags);
|
|
564
|
+
} catch (_e) {
|
|
565
|
+
return void 0;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
542
568
|
};
|
|
543
569
|
|
|
544
570
|
// src/appenders/FileAppender.ts
|
|
@@ -639,8 +665,8 @@ var MatchFilter = class {
|
|
|
639
665
|
*/
|
|
640
666
|
init(config) {
|
|
641
667
|
const cfg = config ?? {};
|
|
642
|
-
this._allow = cfg.allow
|
|
643
|
-
this._deny = cfg.deny
|
|
668
|
+
this._allow = this._prepareRules(cfg.allow);
|
|
669
|
+
this._deny = this._prepareRules(cfg.deny);
|
|
644
670
|
this.enabled = cfg.enabled !== false;
|
|
645
671
|
}
|
|
646
672
|
dispose() {
|
|
@@ -658,13 +684,13 @@ var MatchFilter = class {
|
|
|
658
684
|
if (this._allow && Object.keys(this._allow).length > 0) {
|
|
659
685
|
for (const [path, expected] of Object.entries(this._allow)) {
|
|
660
686
|
const actual = LogM8Utils.getPropertyByPath(logEvent, path);
|
|
661
|
-
if (!this.
|
|
687
|
+
if (!this._matches(actual, expected)) return false;
|
|
662
688
|
}
|
|
663
689
|
}
|
|
664
690
|
if (this._deny && Object.keys(this._deny).length > 0) {
|
|
665
691
|
for (const [path, expected] of Object.entries(this._deny)) {
|
|
666
692
|
const actual = LogM8Utils.getPropertyByPath(logEvent, path);
|
|
667
|
-
if (this.
|
|
693
|
+
if (this._matches(actual, expected)) return false;
|
|
668
694
|
}
|
|
669
695
|
}
|
|
670
696
|
return true;
|
|
@@ -672,6 +698,15 @@ var MatchFilter = class {
|
|
|
672
698
|
return false;
|
|
673
699
|
}
|
|
674
700
|
}
|
|
701
|
+
// Matches actual against expected, supporting RegExp; otherwise deep equality.
|
|
702
|
+
_matches(actual, expected) {
|
|
703
|
+
if (expected instanceof RegExp) {
|
|
704
|
+
if (actual === void 0 || actual === null) return false;
|
|
705
|
+
const asString = typeof actual === "string" ? actual : String(actual);
|
|
706
|
+
return expected.test(asString);
|
|
707
|
+
}
|
|
708
|
+
return this._isEqual(actual, expected);
|
|
709
|
+
}
|
|
675
710
|
// Simple deep equality for primitives, arrays, plain objects, dates
|
|
676
711
|
_isEqual(a, b) {
|
|
677
712
|
if (a === b) return true;
|
|
@@ -702,6 +737,20 @@ var MatchFilter = class {
|
|
|
702
737
|
_isPlainObject(val) {
|
|
703
738
|
return typeof val === "object" && val !== null && !Array.isArray(val) && Object.getPrototypeOf(val) === Object.prototype;
|
|
704
739
|
}
|
|
740
|
+
// Convert rule map values: regex-like strings -> RegExp; leave others as-is.
|
|
741
|
+
_prepareRules(map) {
|
|
742
|
+
if (!map || Object.keys(map).length === 0) return void 0;
|
|
743
|
+
const prepared = {};
|
|
744
|
+
for (const [path, val] of Object.entries(map)) {
|
|
745
|
+
if (typeof val === "string") {
|
|
746
|
+
const rx = LogM8Utils.parseRegexFromString(val);
|
|
747
|
+
prepared[path] = rx ?? val;
|
|
748
|
+
} else {
|
|
749
|
+
prepared[path] = val;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return prepared;
|
|
753
|
+
}
|
|
705
754
|
};
|
|
706
755
|
var MatchFilterFactory = class {
|
|
707
756
|
constructor() {
|