befly 3.21.1 → 3.22.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/lib/logger.js CHANGED
@@ -19,28 +19,12 @@ const RUNTIME_LOG_DIR = nodePathResolve(INITIAL_CWD, "logs");
19
19
  const BUILTIN_SENSITIVE_KEYS = ["*password*", "pass", "pwd", "*token*", "access_token", "refresh_token", "accessToken", "refreshToken", "authorization", "cookie", "set-cookie", "*secret*", "apiKey", "api_key", "privateKey", "private_key"];
20
20
 
21
21
  let sanitizeOptions = {
22
- maxStringLen: 200,
23
- maxArrayItems: 500,
24
22
  sanitizeDepth: 5,
25
23
  sanitizeNodes: 5000,
26
24
  sanitizeObjectKeys: 500,
27
25
  sensitiveKeyMatcher: buildSensitiveKeyMatcher({ builtinPatterns: BUILTIN_SENSITIVE_KEYS, userPatterns: [] })
28
26
  };
29
27
 
30
- function buildSanitizeOptionsForWriteOptions(writeOptions) {
31
- if (!writeOptions || writeOptions.truncate !== false) return sanitizeOptions;
32
-
33
- // 仅关闭“截断”,仍保留敏感字段掩码与结构化清洗(避免泄露敏感信息)。
34
- return {
35
- maxStringLen: 200000,
36
- maxArrayItems: 5000,
37
- sanitizeDepth: sanitizeOptions.sanitizeDepth,
38
- sanitizeNodes: sanitizeOptions.sanitizeNodes,
39
- sanitizeObjectKeys: sanitizeOptions.sanitizeObjectKeys,
40
- sensitiveKeyMatcher: sanitizeOptions.sensitiveKeyMatcher
41
- };
42
- }
43
-
44
28
  let mockInstance = null;
45
29
 
46
30
  let appFileSink = null;
@@ -381,10 +365,8 @@ export function configure(cfg) {
381
365
  appFileSink = null;
382
366
  errorFileSink = null;
383
367
 
384
- // 运行时清洗/截断上限(可配置)
368
+ // 运行时清洗上限:只保留深度/节点/对象键数量保护。
385
369
  sanitizeOptions = {
386
- maxStringLen: normalizePositiveInt(config.maxStringLen, 200, 20, 200000),
387
- maxArrayItems: normalizePositiveInt(config.maxArrayItems, 500, 10, 5000),
388
370
  sanitizeDepth: normalizePositiveInt(config.sanitizeDepth, 5, 1, 10),
389
371
  sanitizeNodes: normalizePositiveInt(config.sanitizeNodes, 5000, 50, 20000),
390
372
  sanitizeObjectKeys: normalizePositiveInt(config.sanitizeObjectKeys, 500, 10, 5000),
@@ -476,16 +458,15 @@ function ensureSinksReady(kind) {
476
458
  return { fileSink: errorFileSink };
477
459
  }
478
460
 
479
- function writeJsonl(kind, level, record, options) {
461
+ function writeJsonl(kind, level, record) {
480
462
  const sinks = ensureSinksReady(kind);
481
463
  const time = Date.now();
482
- const effectiveSanitizeOptions = buildSanitizeOptionsForWriteOptions(options);
483
- const sanitizedRecord = sanitizeLogObject(record, effectiveSanitizeOptions);
464
+ const sanitizedRecord = sanitizeLogObject(record, sanitizeOptions);
484
465
  const fileLine = buildJsonLine(level, time, sanitizedRecord);
485
466
  sinks.fileSink.enqueue(fileLine);
486
467
  }
487
468
 
488
- // 对象清洗/脱敏/截断逻辑已下沉到 utils/loggerUtils.ts(减少 logger.ts 复杂度)。
469
+ // 对象清洗/脱敏逻辑已下沉到 utils/loggerUtils.js(减少 logger.js 复杂度)。
489
470
 
490
471
  // 日志仅接受 1 个入参(任意类型)。
491
472
  // - plain object({})直接作为 record
@@ -519,16 +500,15 @@ function toRecord(input) {
519
500
  }
520
501
  }
521
502
 
522
- function logWrite(level, input, options) {
503
+ function logWrite(level, input) {
523
504
  // debug!=1/true 则不记录 debug 日志
524
505
  if (level === "debug" && config.debug !== 1 && config.debug !== true) return;
525
506
 
526
507
  const record0 = toRecord(input);
527
508
 
528
- // 测试场景:mock logger 走同步写入,并在入口进行清洗/脱敏/截断控制
509
+ // 测试场景:mock logger 走同步写入,并在入口进行清洗/脱敏控制
529
510
  if (mockInstance) {
530
- const effective = buildSanitizeOptionsForWriteOptions(options);
531
- const sanitized = sanitizeLogObject(record0, effective);
511
+ const sanitized = sanitizeLogObject(record0, sanitizeOptions);
532
512
  if (level === "info") {
533
513
  mockInstance.info(sanitized);
534
514
  } else if (level === "warn") {
@@ -543,9 +523,9 @@ function logWrite(level, input, options) {
543
523
 
544
524
  if (level === "error") {
545
525
  // error 仅写入 error 文件
546
- writeJsonl("error", "error", record0, options);
526
+ writeJsonl("error", "error", record0);
547
527
  } else {
548
- writeJsonl("app", level, record0, options);
528
+ writeJsonl("app", level, record0);
549
529
  }
550
530
  }
551
531
 
@@ -553,41 +533,37 @@ function logWrite(level, input, options) {
553
533
  * 日志实例(延迟初始化)
554
534
  */
555
535
  export const Logger = {
556
- info(msg, data, truncate) {
557
- const options = truncate === false ? { truncate: false } : undefined;
536
+ info(msg, data) {
558
537
  if (isPlainObject(msg)) {
559
- logWrite("info", msg, options);
538
+ logWrite("info", msg);
560
539
  return;
561
540
  }
562
541
 
563
- logWrite("info", { msg: msg, data: data }, options);
542
+ logWrite("info", { msg: msg, data: data });
564
543
  },
565
- warn(msg, data, truncate) {
566
- const options = truncate === false ? { truncate: false } : undefined;
544
+ warn(msg, data) {
567
545
  if (isPlainObject(msg)) {
568
- logWrite("warn", msg, options);
546
+ logWrite("warn", msg);
569
547
  return;
570
548
  }
571
549
 
572
- logWrite("warn", { msg: msg, data: data }, options);
550
+ logWrite("warn", { msg: msg, data: data });
573
551
  },
574
- error(msg, err, data, truncate) {
575
- const options = truncate === false ? { truncate: false } : undefined;
552
+ error(msg, err, data) {
576
553
  if (isPlainObject(msg)) {
577
- logWrite("error", msg, options);
554
+ logWrite("error", msg);
578
555
  return;
579
556
  }
580
557
 
581
- logWrite("error", { msg: msg, err: err, data: data }, options);
558
+ logWrite("error", { msg: msg, err: err, data: data });
582
559
  },
583
- debug(msg, data, truncate) {
584
- const options = truncate === false ? { truncate: false } : undefined;
560
+ debug(msg, data) {
585
561
  if (isPlainObject(msg)) {
586
- logWrite("debug", msg, options);
562
+ logWrite("debug", msg);
587
563
  return;
588
564
  }
589
565
 
590
- logWrite("debug", { msg: msg, data: data }, options);
566
+ logWrite("debug", { msg: msg, data: data });
591
567
  },
592
568
  async flush() {
593
569
  await flush();