@rawnodes/logger 2.8.0 → 2.10.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 +127 -17
- package/dist/index.d.mts +32 -230
- package/dist/index.d.ts +32 -230
- package/dist/index.js +233 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -111
- package/dist/index.mjs.map +1 -1
- package/dist/transports/relay.d.mts +14 -0
- package/dist/transports/relay.d.ts +14 -0
- package/dist/transports/relay.js +368 -0
- package/dist/transports/relay.js.map +1 -0
- package/dist/transports/relay.mjs +363 -0
- package/dist/transports/relay.mjs.map +1 -0
- package/dist/types-lfJLhC8J.d.mts +280 -0
- package/dist/types-lfJLhC8J.d.ts +280 -0
- package/package.json +21 -5
package/dist/index.mjs
CHANGED
|
@@ -161,8 +161,10 @@ var DEFAULT_OPTIONS = {
|
|
|
161
161
|
var BaseHttpTransport = class {
|
|
162
162
|
buffer;
|
|
163
163
|
onErrorCallback;
|
|
164
|
+
masker;
|
|
164
165
|
constructor(opts = {}) {
|
|
165
166
|
this.onErrorCallback = opts.onError;
|
|
167
|
+
this.masker = opts.masker;
|
|
166
168
|
this.buffer = new MessageBuffer({
|
|
167
169
|
batchSize: opts.batchSize ?? DEFAULT_OPTIONS.batchSize,
|
|
168
170
|
flushInterval: opts.flushInterval ?? DEFAULT_OPTIONS.flushInterval,
|
|
@@ -197,12 +199,16 @@ var BaseHttpTransport = class {
|
|
|
197
199
|
}
|
|
198
200
|
transformMessage(info) {
|
|
199
201
|
const { level, message, timestamp, context, ...meta } = info;
|
|
202
|
+
let resolvedMeta;
|
|
203
|
+
if (Object.keys(meta).length > 0) {
|
|
204
|
+
resolvedMeta = this.masker ? this.masker(meta) : meta;
|
|
205
|
+
}
|
|
200
206
|
return {
|
|
201
207
|
level,
|
|
202
208
|
message: String(message),
|
|
203
209
|
timestamp: timestamp instanceof Date ? timestamp : timestamp ? new Date(String(timestamp)) : /* @__PURE__ */ new Date(),
|
|
204
210
|
context,
|
|
205
|
-
meta:
|
|
211
|
+
meta: resolvedMeta
|
|
206
212
|
};
|
|
207
213
|
}
|
|
208
214
|
handleError(error, messages) {
|
|
@@ -249,7 +255,7 @@ var DEFAULT_REQUEST_TIMEOUT_MS = 1e4;
|
|
|
249
255
|
var DiscordTransport = class extends BaseHttpTransport {
|
|
250
256
|
config;
|
|
251
257
|
requestTimeout;
|
|
252
|
-
constructor(config) {
|
|
258
|
+
constructor(config, masker) {
|
|
253
259
|
super({
|
|
254
260
|
batchSize: config.batchSize ?? 10,
|
|
255
261
|
flushInterval: config.flushInterval ?? 2e3,
|
|
@@ -258,7 +264,8 @@ var DiscordTransport = class extends BaseHttpTransport {
|
|
|
258
264
|
maxQueueSize: config.maxQueueSize,
|
|
259
265
|
dropPolicy: config.dropPolicy,
|
|
260
266
|
onDrop: config.onDrop,
|
|
261
|
-
onError: config.onError
|
|
267
|
+
onError: config.onError,
|
|
268
|
+
masker
|
|
262
269
|
});
|
|
263
270
|
this.config = config;
|
|
264
271
|
this.requestTimeout = config.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
@@ -398,7 +405,7 @@ var TelegramTransport = class extends BaseHttpTransport {
|
|
|
398
405
|
config;
|
|
399
406
|
apiUrl;
|
|
400
407
|
requestTimeout;
|
|
401
|
-
constructor(config) {
|
|
408
|
+
constructor(config, masker) {
|
|
402
409
|
super({
|
|
403
410
|
batchSize: config.batchSize ?? 20,
|
|
404
411
|
flushInterval: config.flushInterval ?? 1e3,
|
|
@@ -407,7 +414,8 @@ var TelegramTransport = class extends BaseHttpTransport {
|
|
|
407
414
|
maxQueueSize: config.maxQueueSize,
|
|
408
415
|
dropPolicy: config.dropPolicy,
|
|
409
416
|
onDrop: config.onDrop,
|
|
410
|
-
onError: config.onError
|
|
417
|
+
onError: config.onError,
|
|
418
|
+
masker
|
|
411
419
|
});
|
|
412
420
|
this.config = config;
|
|
413
421
|
this.apiUrl = `https://api.telegram.org/bot${config.botToken}`;
|
|
@@ -512,7 +520,7 @@ var ZohoCliqTransport = class extends BaseHttpTransport {
|
|
|
512
520
|
config;
|
|
513
521
|
endpoint;
|
|
514
522
|
requestTimeout;
|
|
515
|
-
constructor(config) {
|
|
523
|
+
constructor(config, masker) {
|
|
516
524
|
super({
|
|
517
525
|
batchSize: config.batchSize ?? 20,
|
|
518
526
|
flushInterval: config.flushInterval ?? 2e3,
|
|
@@ -521,7 +529,8 @@ var ZohoCliqTransport = class extends BaseHttpTransport {
|
|
|
521
529
|
maxQueueSize: config.maxQueueSize,
|
|
522
530
|
dropPolicy: config.dropPolicy,
|
|
523
531
|
onDrop: config.onDrop,
|
|
524
|
-
onError: config.onError
|
|
532
|
+
onError: config.onError,
|
|
533
|
+
masker
|
|
525
534
|
});
|
|
526
535
|
this.config = config;
|
|
527
536
|
this.requestTimeout = config.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS3;
|
|
@@ -643,7 +652,8 @@ var CloudWatchTransport = class extends BaseHttpTransport {
|
|
|
643
652
|
initialized = false;
|
|
644
653
|
initPromise = null;
|
|
645
654
|
resolvedLogStreamName;
|
|
646
|
-
|
|
655
|
+
maskReplacer;
|
|
656
|
+
constructor(config, configHostname, maskReplacerFn) {
|
|
647
657
|
super({
|
|
648
658
|
batchSize: config.batchSize ?? 100,
|
|
649
659
|
flushInterval: config.flushInterval ?? 1e3,
|
|
@@ -654,6 +664,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
|
|
|
654
664
|
onDrop: config.onDrop,
|
|
655
665
|
onError: config.onError
|
|
656
666
|
});
|
|
667
|
+
this.maskReplacer = maskReplacerFn;
|
|
657
668
|
this.config = config;
|
|
658
669
|
this.resolvedLogStreamName = resolveLogStreamName(config.logStreamName, configHostname);
|
|
659
670
|
this.client = new CloudWatchLogsClient({
|
|
@@ -666,6 +677,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
|
|
|
666
677
|
}
|
|
667
678
|
async sendBatch(messages) {
|
|
668
679
|
await this.ensureInitialized();
|
|
680
|
+
const replacer = this.maskReplacer;
|
|
669
681
|
const logEvents = messages.map((msg) => ({
|
|
670
682
|
timestamp: msg.timestamp.getTime(),
|
|
671
683
|
message: JSON.stringify({
|
|
@@ -673,7 +685,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
|
|
|
673
685
|
message: msg.message,
|
|
674
686
|
context: msg.context,
|
|
675
687
|
...msg.meta
|
|
676
|
-
})
|
|
688
|
+
}, replacer)
|
|
677
689
|
}));
|
|
678
690
|
logEvents.sort((a, b) => (a.timestamp ?? 0) - (b.timestamp ?? 0));
|
|
679
691
|
const command = new PutLogEventsCommand({
|
|
@@ -783,13 +795,27 @@ function getLevelName(levelNum) {
|
|
|
783
795
|
if (levelNum >= 20) return "debug";
|
|
784
796
|
return "silly";
|
|
785
797
|
}
|
|
786
|
-
|
|
798
|
+
var DEFAULT_RESPECTS_OVERRIDES = {
|
|
799
|
+
console: true,
|
|
800
|
+
file: true,
|
|
801
|
+
cloudwatch: true,
|
|
802
|
+
relay: true,
|
|
803
|
+
discord: false,
|
|
804
|
+
telegram: false,
|
|
805
|
+
zohoCliq: false
|
|
806
|
+
};
|
|
807
|
+
function resolveRespectsOverrides(kind, configFlag) {
|
|
808
|
+
return configFlag ?? DEFAULT_RESPECTS_OVERRIDES[kind];
|
|
809
|
+
}
|
|
810
|
+
function shouldPassTransport(log, level, rules, state, respectOverrides) {
|
|
787
811
|
const logLevel = getLevelName(log.level);
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
if (embeddedOverride === "
|
|
791
|
-
|
|
792
|
-
|
|
812
|
+
if (respectOverrides) {
|
|
813
|
+
const embeddedOverride = log.__or;
|
|
814
|
+
if (typeof embeddedOverride === "string") {
|
|
815
|
+
if (embeddedOverride === "off") return false;
|
|
816
|
+
const overrideLevel = embeddedOverride;
|
|
817
|
+
return LOG_LEVELS[logLevel] <= LOG_LEVELS[overrideLevel];
|
|
818
|
+
}
|
|
793
819
|
}
|
|
794
820
|
const context = log.context;
|
|
795
821
|
if (rules && rules.length > 0) {
|
|
@@ -811,12 +837,12 @@ function shouldPassTransport(log, level, rules, state) {
|
|
|
811
837
|
return LOG_LEVELS[logLevel] <= LOG_LEVELS[effectiveLevel];
|
|
812
838
|
}
|
|
813
839
|
var RESERVED_LOG_FIELDS = /* @__PURE__ */ new Set(["level", "time", "msg", "context", "__or"]);
|
|
814
|
-
function formatLog(log, format,
|
|
840
|
+
function formatLog(log, format, state) {
|
|
815
841
|
const levelName = getLevelName(log.level);
|
|
816
842
|
const timestamp = new Date(log.time).toISOString();
|
|
817
843
|
const context = log.context || "APP";
|
|
818
844
|
const message = log.msg || "";
|
|
819
|
-
const storeContext = store.getStore();
|
|
845
|
+
const storeContext = state.store.getStore();
|
|
820
846
|
const meta = {};
|
|
821
847
|
for (const [key, value] of Object.entries(log)) {
|
|
822
848
|
if (!RESERVED_LOG_FIELDS.has(key)) {
|
|
@@ -826,6 +852,7 @@ function formatLog(log, format, store) {
|
|
|
826
852
|
if (storeContext) {
|
|
827
853
|
Object.assign(meta, storeContext);
|
|
828
854
|
}
|
|
855
|
+
const replacer = state.maskReplacer;
|
|
829
856
|
if (format === "json") {
|
|
830
857
|
return JSON.stringify({
|
|
831
858
|
level: levelName,
|
|
@@ -833,7 +860,7 @@ function formatLog(log, format, store) {
|
|
|
833
860
|
context,
|
|
834
861
|
message,
|
|
835
862
|
...meta
|
|
836
|
-
}) + "\n";
|
|
863
|
+
}, replacer) + "\n";
|
|
837
864
|
}
|
|
838
865
|
if (format === "plain") {
|
|
839
866
|
const LEVEL_COLORS = {
|
|
@@ -849,10 +876,11 @@ function formatLog(log, format, store) {
|
|
|
849
876
|
const color = LEVEL_COLORS[levelName] || "";
|
|
850
877
|
const coloredLevel = color ? `${color}${levelName}${RESET}` : levelName;
|
|
851
878
|
const formatValue = (key, value) => {
|
|
852
|
-
|
|
853
|
-
|
|
879
|
+
const masked = replacer ? replacer.call(void 0, key, value) : value;
|
|
880
|
+
if (typeof masked === "string" && masked.includes("\n")) {
|
|
881
|
+
return "\n " + masked.split("\n").join("\n ");
|
|
854
882
|
}
|
|
855
|
-
return JSON.stringify(
|
|
883
|
+
return JSON.stringify(masked, replacer);
|
|
856
884
|
};
|
|
857
885
|
const metaStr = Object.keys(meta).length > 0 ? "\n " + Object.entries(meta).map(([k, v]) => `${k}: ${formatValue(k, v)}`).join("\n ") : "";
|
|
858
886
|
return `[${timestamp}] ${coloredLevel} [${context}] ${message}${metaStr}
|
|
@@ -861,14 +889,15 @@ function formatLog(log, format, store) {
|
|
|
861
889
|
if (format === "logfmt") {
|
|
862
890
|
const parts = [`level=${levelName}`, `msg="${message}"`, `context=${context}`, `ts=${timestamp}`];
|
|
863
891
|
for (const [k, v] of Object.entries(meta)) {
|
|
864
|
-
|
|
892
|
+
const masked = replacer ? replacer.call(void 0, k, v) : v;
|
|
893
|
+
parts.push(`${k}=${JSON.stringify(masked, replacer)}`);
|
|
865
894
|
}
|
|
866
895
|
return parts.join(" ") + "\n";
|
|
867
896
|
}
|
|
868
897
|
return `[${timestamp}] ${levelName}: ${message}
|
|
869
898
|
`;
|
|
870
899
|
}
|
|
871
|
-
function createFormattedFilterStream(format, level, rules, state, destination) {
|
|
900
|
+
function createFormattedFilterStream(format, level, rules, state, destination, respectOverrides) {
|
|
872
901
|
return new Transform({
|
|
873
902
|
transform(chunk, _encoding, callback) {
|
|
874
903
|
const line = chunk.toString().trim();
|
|
@@ -881,11 +910,11 @@ function createFormattedFilterStream(format, level, rules, state, destination) {
|
|
|
881
910
|
callback();
|
|
882
911
|
return;
|
|
883
912
|
}
|
|
884
|
-
if (!shouldPassTransport(log, level, rules, state)) {
|
|
913
|
+
if (!shouldPassTransport(log, level, rules, state, respectOverrides)) {
|
|
885
914
|
callback();
|
|
886
915
|
return;
|
|
887
916
|
}
|
|
888
|
-
const formatted = formatLog(log, format, state
|
|
917
|
+
const formatted = formatLog(log, format, state);
|
|
889
918
|
destination.write(formatted);
|
|
890
919
|
callback();
|
|
891
920
|
}
|
|
@@ -899,7 +928,8 @@ function createStreams(config, state) {
|
|
|
899
928
|
config.console.level,
|
|
900
929
|
config.console.rules,
|
|
901
930
|
state,
|
|
902
|
-
process.stdout
|
|
931
|
+
process.stdout,
|
|
932
|
+
resolveRespectsOverrides("console", config.console.respectRuntimeOverrides)
|
|
903
933
|
);
|
|
904
934
|
streams.push({
|
|
905
935
|
level: "trace",
|
|
@@ -932,7 +962,8 @@ function createStreams(config, state) {
|
|
|
932
962
|
fileConfig.level,
|
|
933
963
|
fileConfig.rules,
|
|
934
964
|
state,
|
|
935
|
-
rotatingStream
|
|
965
|
+
rotatingStream,
|
|
966
|
+
resolveRespectsOverrides("file", fileConfig.respectRuntimeOverrides)
|
|
936
967
|
);
|
|
937
968
|
streams.push({
|
|
938
969
|
level: "trace",
|
|
@@ -940,36 +971,60 @@ function createStreams(config, state) {
|
|
|
940
971
|
});
|
|
941
972
|
}
|
|
942
973
|
for (const discordConfig of toArray(config.discord)) {
|
|
943
|
-
const transport = new DiscordTransport(discordConfig);
|
|
974
|
+
const transport = new DiscordTransport(discordConfig, state.maskerFn);
|
|
944
975
|
transports.push(transport);
|
|
945
|
-
const discordStream = createHttpTransportStream(
|
|
976
|
+
const discordStream = createHttpTransportStream(
|
|
977
|
+
transport,
|
|
978
|
+
discordConfig.level,
|
|
979
|
+
discordConfig.rules,
|
|
980
|
+
state,
|
|
981
|
+
resolveRespectsOverrides("discord", discordConfig.respectRuntimeOverrides)
|
|
982
|
+
);
|
|
946
983
|
streams.push({
|
|
947
984
|
level: "trace",
|
|
948
985
|
stream: discordStream
|
|
949
986
|
});
|
|
950
987
|
}
|
|
951
988
|
for (const telegramConfig of toArray(config.telegram)) {
|
|
952
|
-
const transport = new TelegramTransport(telegramConfig);
|
|
989
|
+
const transport = new TelegramTransport(telegramConfig, state.maskerFn);
|
|
953
990
|
transports.push(transport);
|
|
954
|
-
const telegramStream = createHttpTransportStream(
|
|
991
|
+
const telegramStream = createHttpTransportStream(
|
|
992
|
+
transport,
|
|
993
|
+
telegramConfig.level,
|
|
994
|
+
telegramConfig.rules,
|
|
995
|
+
state,
|
|
996
|
+
resolveRespectsOverrides("telegram", telegramConfig.respectRuntimeOverrides)
|
|
997
|
+
);
|
|
955
998
|
streams.push({
|
|
956
999
|
level: "trace",
|
|
957
1000
|
stream: telegramStream
|
|
958
1001
|
});
|
|
959
1002
|
}
|
|
960
1003
|
for (const zohoCliqConfig of toArray(config.zohoCliq)) {
|
|
961
|
-
const transport = new ZohoCliqTransport(zohoCliqConfig);
|
|
1004
|
+
const transport = new ZohoCliqTransport(zohoCliqConfig, state.maskerFn);
|
|
962
1005
|
transports.push(transport);
|
|
963
|
-
const zohoStream = createHttpTransportStream(
|
|
1006
|
+
const zohoStream = createHttpTransportStream(
|
|
1007
|
+
transport,
|
|
1008
|
+
zohoCliqConfig.level,
|
|
1009
|
+
zohoCliqConfig.rules,
|
|
1010
|
+
state,
|
|
1011
|
+
resolveRespectsOverrides("zohoCliq", zohoCliqConfig.respectRuntimeOverrides)
|
|
1012
|
+
);
|
|
964
1013
|
streams.push({
|
|
965
1014
|
level: "trace",
|
|
966
1015
|
stream: zohoStream
|
|
967
1016
|
});
|
|
968
1017
|
}
|
|
969
1018
|
for (const cloudwatchConfig of toArray(config.cloudwatch)) {
|
|
970
|
-
const transport = new CloudWatchTransport(cloudwatchConfig, config.hostname);
|
|
1019
|
+
const transport = new CloudWatchTransport(cloudwatchConfig, config.hostname, state.maskReplacer);
|
|
971
1020
|
transports.push(transport);
|
|
972
|
-
const cwStream = createHttpTransportStream(
|
|
1021
|
+
const cwStream = createHttpTransportStream(
|
|
1022
|
+
transport,
|
|
1023
|
+
cloudwatchConfig.level,
|
|
1024
|
+
cloudwatchConfig.rules,
|
|
1025
|
+
state,
|
|
1026
|
+
resolveRespectsOverrides("cloudwatch", cloudwatchConfig.respectRuntimeOverrides)
|
|
1027
|
+
);
|
|
973
1028
|
streams.push({
|
|
974
1029
|
level: "trace",
|
|
975
1030
|
stream: cwStream
|
|
@@ -994,7 +1049,7 @@ function toArray(value) {
|
|
|
994
1049
|
if (!value) return [];
|
|
995
1050
|
return Array.isArray(value) ? value : [value];
|
|
996
1051
|
}
|
|
997
|
-
function createHttpTransportStream(transport, level, rules, state) {
|
|
1052
|
+
function createHttpTransportStream(transport, level, rules, state, respectOverrides) {
|
|
998
1053
|
return new Writable({
|
|
999
1054
|
write(chunk, _encoding, callback) {
|
|
1000
1055
|
const line = chunk.toString().trim();
|
|
@@ -1007,7 +1062,7 @@ function createHttpTransportStream(transport, level, rules, state) {
|
|
|
1007
1062
|
callback();
|
|
1008
1063
|
return;
|
|
1009
1064
|
}
|
|
1010
|
-
if (!shouldPassTransport(log, level, rules, state)) {
|
|
1065
|
+
if (!shouldPassTransport(log, level, rules, state, respectOverrides)) {
|
|
1011
1066
|
callback();
|
|
1012
1067
|
return;
|
|
1013
1068
|
}
|
|
@@ -1033,6 +1088,116 @@ function createHttpTransportStream(transport, level, rules, state) {
|
|
|
1033
1088
|
});
|
|
1034
1089
|
}
|
|
1035
1090
|
|
|
1091
|
+
// src/utils/mask-secrets.ts
|
|
1092
|
+
var DEFAULT_SECRET_PATTERNS = [
|
|
1093
|
+
"password",
|
|
1094
|
+
"secret",
|
|
1095
|
+
"token",
|
|
1096
|
+
"apikey",
|
|
1097
|
+
"api_key",
|
|
1098
|
+
"api-key",
|
|
1099
|
+
"auth",
|
|
1100
|
+
"credential",
|
|
1101
|
+
"private"
|
|
1102
|
+
];
|
|
1103
|
+
var DEFAULT_MASK = "***";
|
|
1104
|
+
var REGEX_ESCAPE_RE = /[.*+?^${}()|[\]\\]/g;
|
|
1105
|
+
function buildSecretRe(patterns) {
|
|
1106
|
+
const escaped = patterns.map((p) => p.replace(REGEX_ESCAPE_RE, "\\$&"));
|
|
1107
|
+
return new RegExp(escaped.join("|"), "i");
|
|
1108
|
+
}
|
|
1109
|
+
var DEFAULT_SECRET_RE = buildSecretRe(DEFAULT_SECRET_PATTERNS);
|
|
1110
|
+
var DEFAULT_RESOLVED = {
|
|
1111
|
+
secretRe: DEFAULT_SECRET_RE,
|
|
1112
|
+
mask: DEFAULT_MASK,
|
|
1113
|
+
deep: true
|
|
1114
|
+
};
|
|
1115
|
+
function resolveOptions(options) {
|
|
1116
|
+
if (options.patterns === void 0 && options.mask === void 0 && options.deep === void 0) {
|
|
1117
|
+
return DEFAULT_RESOLVED;
|
|
1118
|
+
}
|
|
1119
|
+
const { patterns = DEFAULT_SECRET_PATTERNS, mask = DEFAULT_MASK, deep = true } = options;
|
|
1120
|
+
return {
|
|
1121
|
+
secretRe: patterns === DEFAULT_SECRET_PATTERNS ? DEFAULT_SECRET_RE : buildSecretRe(patterns),
|
|
1122
|
+
mask,
|
|
1123
|
+
deep
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function isSecretKey(key, secretRe) {
|
|
1127
|
+
return secretRe.test(key);
|
|
1128
|
+
}
|
|
1129
|
+
function maskUrlCredentials(url, mask) {
|
|
1130
|
+
try {
|
|
1131
|
+
const parsed = new URL(url);
|
|
1132
|
+
if (parsed.password) {
|
|
1133
|
+
parsed.password = mask;
|
|
1134
|
+
}
|
|
1135
|
+
if (parsed.username && parsed.password) {
|
|
1136
|
+
parsed.username = mask;
|
|
1137
|
+
}
|
|
1138
|
+
return parsed.toString();
|
|
1139
|
+
} catch {
|
|
1140
|
+
return url;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
function maskString(str, mask) {
|
|
1144
|
+
if (str.length < 10) return str;
|
|
1145
|
+
if (str.charCodeAt(0) !== 104) return str;
|
|
1146
|
+
if (!str.startsWith("http://") && !str.startsWith("https://")) return str;
|
|
1147
|
+
if (str.indexOf("@") === -1) return str;
|
|
1148
|
+
return maskUrlCredentials(str, mask);
|
|
1149
|
+
}
|
|
1150
|
+
function maskInternal(obj, opts) {
|
|
1151
|
+
if (obj === null || obj === void 0) return obj;
|
|
1152
|
+
const t = typeof obj;
|
|
1153
|
+
if (t === "string") return maskString(obj, opts.mask);
|
|
1154
|
+
if (t !== "object") return obj;
|
|
1155
|
+
if (Array.isArray(obj)) {
|
|
1156
|
+
return opts.deep ? obj.map((item) => maskInternal(item, opts)) : obj;
|
|
1157
|
+
}
|
|
1158
|
+
const { secretRe, mask, deep } = opts;
|
|
1159
|
+
const result = {};
|
|
1160
|
+
const syms = Object.getOwnPropertySymbols(obj);
|
|
1161
|
+
for (let i = 0; i < syms.length; i++) {
|
|
1162
|
+
const sym = syms[i];
|
|
1163
|
+
result[sym] = obj[sym];
|
|
1164
|
+
}
|
|
1165
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1166
|
+
if (isSecretKey(key, secretRe)) {
|
|
1167
|
+
result[key] = mask;
|
|
1168
|
+
continue;
|
|
1169
|
+
}
|
|
1170
|
+
const vt = typeof value;
|
|
1171
|
+
if (vt === "string") {
|
|
1172
|
+
result[key] = maskString(value, mask);
|
|
1173
|
+
} else if (deep && vt === "object" && value !== null) {
|
|
1174
|
+
result[key] = maskInternal(value, opts);
|
|
1175
|
+
} else {
|
|
1176
|
+
result[key] = value;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
return result;
|
|
1180
|
+
}
|
|
1181
|
+
function maskSecrets(obj, options = {}) {
|
|
1182
|
+
return maskInternal(obj, resolveOptions(options));
|
|
1183
|
+
}
|
|
1184
|
+
function createMasker(options = {}) {
|
|
1185
|
+
const opts = resolveOptions(options);
|
|
1186
|
+
return (obj) => maskInternal(obj, opts);
|
|
1187
|
+
}
|
|
1188
|
+
function maskReplacer(options = {}) {
|
|
1189
|
+
const { secretRe, mask } = resolveOptions(options);
|
|
1190
|
+
return function(key, value) {
|
|
1191
|
+
if (key !== "" && secretRe.test(key)) return mask;
|
|
1192
|
+
if (typeof value !== "string") return value;
|
|
1193
|
+
if (value.length < 10) return value;
|
|
1194
|
+
if (value.charCodeAt(0) !== 104) return value;
|
|
1195
|
+
if (!value.startsWith("http://") && !value.startsWith("https://")) return value;
|
|
1196
|
+
if (value.indexOf("@") === -1) return value;
|
|
1197
|
+
return maskUrlCredentials(value, mask);
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1036
1201
|
// src/state.ts
|
|
1037
1202
|
var CUSTOM_LEVELS = {
|
|
1038
1203
|
http: 25,
|
|
@@ -1081,6 +1246,7 @@ function createState(config, store) {
|
|
|
1081
1246
|
levelOverrides.set(key, rule);
|
|
1082
1247
|
}
|
|
1083
1248
|
const { contextIndex, complexRules } = buildIndexes(levelOverrides);
|
|
1249
|
+
const maskOptions = config.maskSecrets === true ? {} : config.maskSecrets || void 0;
|
|
1084
1250
|
const state = {
|
|
1085
1251
|
pino: null,
|
|
1086
1252
|
store: loggerStore,
|
|
@@ -1089,7 +1255,9 @@ function createState(config, store) {
|
|
|
1089
1255
|
contextIndex,
|
|
1090
1256
|
complexRules,
|
|
1091
1257
|
callerConfig: void 0,
|
|
1092
|
-
transports: []
|
|
1258
|
+
transports: [],
|
|
1259
|
+
maskReplacer: maskOptions ? maskReplacer(maskOptions) : void 0,
|
|
1260
|
+
maskerFn: maskOptions ? createMasker(maskOptions) : void 0
|
|
1093
1261
|
};
|
|
1094
1262
|
const { destination, transports } = createStreams(config, state);
|
|
1095
1263
|
state.transports = transports;
|
|
@@ -1166,12 +1334,14 @@ var LevelRuleSchema = z.object({
|
|
|
1166
1334
|
var ConsoleConfigSchema = z.object({
|
|
1167
1335
|
format: LogFormatSchema,
|
|
1168
1336
|
level: LogLevelSchema.optional(),
|
|
1169
|
-
rules: z.array(LevelRuleSchema).optional()
|
|
1337
|
+
rules: z.array(LevelRuleSchema).optional(),
|
|
1338
|
+
respectRuntimeOverrides: z.boolean().optional()
|
|
1170
1339
|
});
|
|
1171
1340
|
var FileConfigSchema = z.object({
|
|
1172
1341
|
format: LogFormatSchema,
|
|
1173
1342
|
level: LogLevelSchema.optional(),
|
|
1174
1343
|
rules: z.array(LevelRuleSchema).optional(),
|
|
1344
|
+
respectRuntimeOverrides: z.boolean().optional(),
|
|
1175
1345
|
dirname: z.string().min(1, "dirname is required"),
|
|
1176
1346
|
filename: z.string().min(1, "filename is required"),
|
|
1177
1347
|
datePattern: z.string().optional(),
|
|
@@ -1183,6 +1353,7 @@ var FileConfigSchema = z.object({
|
|
|
1183
1353
|
var HttpTransportBaseConfigSchema = z.object({
|
|
1184
1354
|
level: LogLevelSchema.optional(),
|
|
1185
1355
|
rules: z.array(LevelRuleSchema).optional(),
|
|
1356
|
+
respectRuntimeOverrides: z.boolean().optional(),
|
|
1186
1357
|
batchSize: z.number().int().positive().optional(),
|
|
1187
1358
|
flushInterval: z.number().int().positive().optional(),
|
|
1188
1359
|
maxRetries: z.number().int().nonnegative().optional(),
|
|
@@ -1196,6 +1367,7 @@ var HttpTransportBaseConfigSchema = z.object({
|
|
|
1196
1367
|
var DiscordConfigSchema = z.object({
|
|
1197
1368
|
level: LogLevelSchema.optional(),
|
|
1198
1369
|
rules: z.array(LevelRuleSchema).optional(),
|
|
1370
|
+
respectRuntimeOverrides: z.boolean().optional(),
|
|
1199
1371
|
batchSize: z.number().int().positive().optional(),
|
|
1200
1372
|
flushInterval: z.number().int().positive().optional(),
|
|
1201
1373
|
maxRetries: z.number().int().nonnegative().optional(),
|
|
@@ -1217,6 +1389,7 @@ var DiscordConfigSchema = z.object({
|
|
|
1217
1389
|
var TelegramConfigSchema = z.object({
|
|
1218
1390
|
level: LogLevelSchema.optional(),
|
|
1219
1391
|
rules: z.array(LevelRuleSchema).optional(),
|
|
1392
|
+
respectRuntimeOverrides: z.boolean().optional(),
|
|
1220
1393
|
batchSize: z.number().int().positive().optional(),
|
|
1221
1394
|
flushInterval: z.number().int().positive().optional(),
|
|
1222
1395
|
maxRetries: z.number().int().nonnegative().optional(),
|
|
@@ -1254,6 +1427,7 @@ var LogStreamNameSchema = z.union([
|
|
|
1254
1427
|
var CloudWatchConfigSchema = z.object({
|
|
1255
1428
|
level: LogLevelSchema.optional(),
|
|
1256
1429
|
rules: z.array(LevelRuleSchema).optional(),
|
|
1430
|
+
respectRuntimeOverrides: z.boolean().optional(),
|
|
1257
1431
|
batchSize: z.number().int().positive().optional(),
|
|
1258
1432
|
flushInterval: z.number().int().positive().optional(),
|
|
1259
1433
|
maxRetries: z.number().int().nonnegative().optional(),
|
|
@@ -1274,6 +1448,7 @@ var CloudWatchConfigSchema = z.object({
|
|
|
1274
1448
|
var ZohoCliqConfigBaseSchema = z.object({
|
|
1275
1449
|
level: LogLevelSchema.optional(),
|
|
1276
1450
|
rules: z.array(LevelRuleSchema).optional(),
|
|
1451
|
+
respectRuntimeOverrides: z.boolean().optional(),
|
|
1277
1452
|
batchSize: z.number().int().positive().optional(),
|
|
1278
1453
|
flushInterval: z.number().int().positive().optional(),
|
|
1279
1454
|
maxRetries: z.number().int().nonnegative().optional(),
|
|
@@ -1306,7 +1481,17 @@ var RelayConfigSchema = z.object({
|
|
|
1306
1481
|
pollInterval: z.number().int().positive().optional(),
|
|
1307
1482
|
bufferSize: z.number().int().positive().optional(),
|
|
1308
1483
|
reconnectDelay: z.number().int().positive().optional(),
|
|
1309
|
-
maxReconnectDelay: z.number().int().positive().optional()
|
|
1484
|
+
maxReconnectDelay: z.number().int().positive().optional(),
|
|
1485
|
+
respectRuntimeOverrides: z.boolean().optional(),
|
|
1486
|
+
allowedWsHosts: z.array(z.string()).optional(),
|
|
1487
|
+
maskSecrets: z.union([
|
|
1488
|
+
z.boolean(),
|
|
1489
|
+
z.object({
|
|
1490
|
+
patterns: z.array(z.string()).optional(),
|
|
1491
|
+
mask: z.string().optional(),
|
|
1492
|
+
deep: z.boolean().optional()
|
|
1493
|
+
})
|
|
1494
|
+
]).optional()
|
|
1310
1495
|
});
|
|
1311
1496
|
var LevelConfigObjectSchema = z.object({
|
|
1312
1497
|
default: LogLevelSchema,
|
|
@@ -1324,6 +1509,11 @@ var AutoShutdownConfigSchema = z.object({
|
|
|
1324
1509
|
timeout: z.number().int().positive().optional(),
|
|
1325
1510
|
signals: z.array(z.string()).optional()
|
|
1326
1511
|
});
|
|
1512
|
+
var MaskSecretsOptionsSchema = z.object({
|
|
1513
|
+
patterns: z.array(z.string()).optional(),
|
|
1514
|
+
mask: z.string().optional(),
|
|
1515
|
+
deep: z.boolean().optional()
|
|
1516
|
+
});
|
|
1327
1517
|
var LoggerConfigSchema = z.object({
|
|
1328
1518
|
level: LevelConfigSchema,
|
|
1329
1519
|
console: ConsoleConfigSchema,
|
|
@@ -1335,7 +1525,8 @@ var LoggerConfigSchema = z.object({
|
|
|
1335
1525
|
relay: RelayConfigSchema.optional(),
|
|
1336
1526
|
caller: z.union([z.boolean(), CallerConfigSchema]).optional(),
|
|
1337
1527
|
hostname: z.string().optional(),
|
|
1338
|
-
autoShutdown: z.union([z.boolean(), AutoShutdownConfigSchema]).optional()
|
|
1528
|
+
autoShutdown: z.union([z.boolean(), AutoShutdownConfigSchema]).optional(),
|
|
1529
|
+
maskSecrets: z.union([z.boolean(), MaskSecretsOptionsSchema]).optional()
|
|
1339
1530
|
});
|
|
1340
1531
|
function validateConfig(config) {
|
|
1341
1532
|
return LoggerConfigSchema.parse(config);
|
|
@@ -1873,75 +2064,6 @@ function getOrGenerateRequestId(headers, options = {}) {
|
|
|
1873
2064
|
return extractRequestId(headers) ?? generateRequestId(options);
|
|
1874
2065
|
}
|
|
1875
2066
|
|
|
1876
|
-
// src/utils/mask-secrets.ts
|
|
1877
|
-
var DEFAULT_SECRET_PATTERNS = [
|
|
1878
|
-
"password",
|
|
1879
|
-
"secret",
|
|
1880
|
-
"token",
|
|
1881
|
-
"apikey",
|
|
1882
|
-
"api_key",
|
|
1883
|
-
"api-key",
|
|
1884
|
-
"auth",
|
|
1885
|
-
"credential",
|
|
1886
|
-
"private"
|
|
1887
|
-
];
|
|
1888
|
-
var DEFAULT_MASK = "***";
|
|
1889
|
-
function isSecretKey(key, patterns) {
|
|
1890
|
-
const lowerKey = key.toLowerCase();
|
|
1891
|
-
return patterns.some((pattern) => lowerKey.includes(pattern.toLowerCase()));
|
|
1892
|
-
}
|
|
1893
|
-
function maskUrlCredentials(url, mask) {
|
|
1894
|
-
try {
|
|
1895
|
-
const parsed = new URL(url);
|
|
1896
|
-
if (parsed.password) {
|
|
1897
|
-
parsed.password = mask;
|
|
1898
|
-
}
|
|
1899
|
-
if (parsed.username && parsed.password) {
|
|
1900
|
-
parsed.username = mask;
|
|
1901
|
-
}
|
|
1902
|
-
return parsed.toString();
|
|
1903
|
-
} catch {
|
|
1904
|
-
return url;
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
function maskSecrets(obj, options = {}) {
|
|
1908
|
-
const { patterns = DEFAULT_SECRET_PATTERNS, mask = DEFAULT_MASK, deep = true } = options;
|
|
1909
|
-
if (obj === null || obj === void 0) {
|
|
1910
|
-
return obj;
|
|
1911
|
-
}
|
|
1912
|
-
if (typeof obj === "string") {
|
|
1913
|
-
if (obj.startsWith("http://") || obj.startsWith("https://")) {
|
|
1914
|
-
return maskUrlCredentials(obj, mask);
|
|
1915
|
-
}
|
|
1916
|
-
return obj;
|
|
1917
|
-
}
|
|
1918
|
-
if (Array.isArray(obj)) {
|
|
1919
|
-
return deep ? obj.map((item) => maskSecrets(item, options)) : obj;
|
|
1920
|
-
}
|
|
1921
|
-
if (typeof obj === "object") {
|
|
1922
|
-
const result = {};
|
|
1923
|
-
for (const sym of Object.getOwnPropertySymbols(obj)) {
|
|
1924
|
-
result[sym] = obj[sym];
|
|
1925
|
-
}
|
|
1926
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
1927
|
-
if (isSecretKey(key, patterns)) {
|
|
1928
|
-
result[key] = mask;
|
|
1929
|
-
} else if (deep && typeof value === "object" && value !== null) {
|
|
1930
|
-
result[key] = maskSecrets(value, options);
|
|
1931
|
-
} else if (typeof value === "string") {
|
|
1932
|
-
result[key] = maskSecrets(value, options);
|
|
1933
|
-
} else {
|
|
1934
|
-
result[key] = value;
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
return result;
|
|
1938
|
-
}
|
|
1939
|
-
return obj;
|
|
1940
|
-
}
|
|
1941
|
-
function createMasker(options = {}) {
|
|
1942
|
-
return (obj) => maskSecrets(obj, options);
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
2067
|
// src/formatters.ts
|
|
1946
2068
|
var MAX_FLATTEN_DEPTH = 10;
|
|
1947
2069
|
var CIRCULAR_REF = "[Circular]";
|
|
@@ -1993,6 +2115,6 @@ function formatLogfmt(data) {
|
|
|
1993
2115
|
return Object.entries(flattened).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${formatLogfmtValue(value)}`).join(" ");
|
|
1994
2116
|
}
|
|
1995
2117
|
|
|
1996
|
-
export { AutoShutdownConfigSchema, BaseHttpTransport, CallerConfigSchema, CloudWatchConfigSchema, CloudWatchTransport, ConsoleConfigSchema, DiscordConfigSchema, DiscordTransport, FileConfigSchema, HttpTransportBaseConfigSchema, LOG_LEVELS, LevelConfigObjectSchema, LevelConfigSchema, LevelRuleSchema, LogFormatSchema, LogLevelSchema, LogStreamNameSchema, LogStreamPatternConfigSchema, LogStreamPatternSchema, LogStreamTemplateConfigSchema, Logger, LoggerConfigSchema, LoggerStore, MessageBuffer, RelayConfigSchema, TelegramConfigSchema, TelegramTransport, ZohoCliqConfigSchema, ZohoCliqTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
|
|
2118
|
+
export { AutoShutdownConfigSchema, BaseHttpTransport, CallerConfigSchema, CloudWatchConfigSchema, CloudWatchTransport, ConsoleConfigSchema, DiscordConfigSchema, DiscordTransport, FileConfigSchema, HttpTransportBaseConfigSchema, LOG_LEVELS, LevelConfigObjectSchema, LevelConfigSchema, LevelRuleSchema, LogFormatSchema, LogLevelSchema, LogStreamNameSchema, LogStreamPatternConfigSchema, LogStreamPatternSchema, LogStreamTemplateConfigSchema, Logger, LoggerConfigSchema, LoggerStore, MessageBuffer, RelayConfigSchema, TelegramConfigSchema, TelegramTransport, ZohoCliqConfigSchema, ZohoCliqTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskReplacer, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
|
|
1997
2119
|
//# sourceMappingURL=index.mjs.map
|
|
1998
2120
|
//# sourceMappingURL=index.mjs.map
|