befly 3.15.24 → 3.15.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.
package/dist/befly.js CHANGED
@@ -499,6 +499,20 @@ import { createWriteStream, existsSync, mkdirSync } from "fs";
499
499
  import { stat } from "fs/promises";
500
500
  import { hostname as osHostname } from "os";
501
501
  import { isAbsolute as nodePathIsAbsolute, join as nodePathJoin, resolve as nodePathResolve } from "path";
502
+ function buildSanitizeOptionsForWrite(writeOptions) {
503
+ if (!writeOptions)
504
+ return sanitizeOptions;
505
+ if (writeOptions.truncate !== false)
506
+ return sanitizeOptions;
507
+ return {
508
+ maxStringLen: 200000,
509
+ maxArrayItems: 5000,
510
+ sanitizeDepth: sanitizeOptions.sanitizeDepth,
511
+ sanitizeNodes: sanitizeOptions.sanitizeNodes,
512
+ sanitizeObjectKeys: sanitizeOptions.sanitizeObjectKeys,
513
+ sensitiveKeyMatcher: sanitizeOptions.sensitiveKeyMatcher
514
+ };
515
+ }
502
516
  function safeWriteStderr(msg) {
503
517
  try {
504
518
  process.stderr.write(`${msg}
@@ -964,7 +978,16 @@ function createSinkLogger(options) {
964
978
  if (level === "debug" && config.debug !== 1)
965
979
  return;
966
980
  const input = isPlainObject(record) ? record : { value: record };
967
- const sanitizedRecord = sanitizeLogObject(input, sanitizeOptions);
981
+ let writeOptions = null;
982
+ if (input && isPlainObject(input)) {
983
+ const raw = input["__loggerWriteOptions"];
984
+ if (raw && isPlainObject(raw)) {
985
+ writeOptions = raw;
986
+ delete input["__loggerWriteOptions"];
987
+ }
988
+ }
989
+ const effectiveSanitizeOptions = buildSanitizeOptionsForWrite(writeOptions);
990
+ const sanitizedRecord = sanitizeLogObject(input, effectiveSanitizeOptions);
968
991
  const line = buildLogLine(level, sanitizedRecord);
969
992
  fileSink.enqueue(line);
970
993
  if (consoleSink)
@@ -1046,34 +1069,47 @@ function withRequestMetaRecord(record) {
1046
1069
  }
1047
1070
 
1048
1071
  class LoggerFacade {
1049
- maybeSanitizeForMock(record) {
1072
+ maybeSanitizeForMock(record, options) {
1050
1073
  if (!mockInstance)
1051
1074
  return record;
1052
- return sanitizeLogObject(record, sanitizeOptions);
1075
+ const effective = buildSanitizeOptionsForWrite(options ? options : null);
1076
+ return sanitizeLogObject(record, effective);
1053
1077
  }
1054
- info(input) {
1078
+ info(input, options) {
1055
1079
  const record0 = withRequestMetaRecord(toRecord(input));
1056
- const record = this.maybeSanitizeForMock(record0);
1080
+ if (!mockInstance && options && isPlainObject(options)) {
1081
+ record0["__loggerWriteOptions"] = options;
1082
+ }
1083
+ const record = this.maybeSanitizeForMock(record0, options);
1057
1084
  getSink("app").info(record);
1058
1085
  }
1059
- warn(input) {
1086
+ warn(input, options) {
1060
1087
  const record0 = withRequestMetaRecord(toRecord(input));
1061
- const record = this.maybeSanitizeForMock(record0);
1088
+ if (!mockInstance && options && isPlainObject(options)) {
1089
+ record0["__loggerWriteOptions"] = options;
1090
+ }
1091
+ const record = this.maybeSanitizeForMock(record0, options);
1062
1092
  getSink("app").warn(record);
1063
1093
  }
1064
- error(input) {
1094
+ error(input, options) {
1065
1095
  const record0 = withRequestMetaRecord(toRecord(input));
1066
- const record = this.maybeSanitizeForMock(record0);
1096
+ if (!mockInstance && options && isPlainObject(options)) {
1097
+ record0["__loggerWriteOptions"] = options;
1098
+ }
1099
+ const record = this.maybeSanitizeForMock(record0, options);
1067
1100
  getSink("app").error(record);
1068
1101
  if (mockInstance)
1069
1102
  return;
1070
1103
  getSink("error").error(record);
1071
1104
  }
1072
- debug(input) {
1105
+ debug(input, options) {
1073
1106
  if (config.debug !== 1)
1074
1107
  return;
1075
1108
  const record0 = withRequestMetaRecord(toRecord(input));
1076
- const record = this.maybeSanitizeForMock(record0);
1109
+ if (!mockInstance && options && isPlainObject(options)) {
1110
+ record0["__loggerWriteOptions"] = options;
1111
+ }
1112
+ const record = this.maybeSanitizeForMock(record0, options);
1077
1113
  getSink("app").debug(record);
1078
1114
  }
1079
1115
  async flush() {
@@ -10876,9 +10912,7 @@ class SyncTable {
10876
10912
  noLog: true,
10877
10913
  meta: {
10878
10914
  subsystem: "syncTable",
10879
- operation: "precheck",
10880
- incompatibleTypeChangeCount: incompatibleTypeChanges.length,
10881
- incompatibleTypeChanges
10915
+ operation: "precheck"
10882
10916
  }
10883
10917
  });
10884
10918
  }
@@ -16562,16 +16596,11 @@ class Befly {
16562
16596
  let kind = "runtime";
16563
16597
  let alreadyLogged = false;
16564
16598
  let noLog = false;
16565
- let incompatibleTypeChanges = null;
16566
- let incompatibleTypeChangeCount = null;
16599
+ const incompatibleTypeChangeLines = [];
16567
16600
  if (isCoreError(error)) {
16568
16601
  kind = error.kind;
16569
16602
  alreadyLogged = error.logged === true;
16570
16603
  noLog = error.noLog === true;
16571
- if (error.meta && typeof error.meta === "object") {
16572
- incompatibleTypeChanges = error.meta["incompatibleTypeChanges"] ?? null;
16573
- incompatibleTypeChangeCount = error.meta["incompatibleTypeChangeCount"] ?? null;
16574
- }
16575
16604
  } else {
16576
16605
  const anyErr = error;
16577
16606
  if (anyErr && anyErr.__syncTableLogged === true) {
@@ -16587,32 +16616,50 @@ class Befly {
16587
16616
  noLog = true;
16588
16617
  }
16589
16618
  }
16619
+ {
16620
+ const text = String(errMessage || "");
16621
+ const parts = text.split(`
16622
+ `);
16623
+ for (const p of parts) {
16624
+ const line = String(p || "").trim();
16625
+ if (line.startsWith("- ")) {
16626
+ incompatibleTypeChangeLines.push(line);
16627
+ }
16628
+ }
16629
+ }
16630
+ const errorMessageFirstLine = String(errMessage || "").split(`
16631
+ `)[0] || "";
16590
16632
  if (alreadyLogged) {
16591
16633
  Logger.error({
16592
16634
  msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25\uFF08\u4E0B\u5C42\u5DF2\u8BB0\u5F55\uFF09",
16593
16635
  errorKind: kind,
16594
- errorMessage: errMessage,
16595
- incompatibleTypeChangeCount,
16596
- incompatibleTypeChanges
16636
+ errorMessage: errorMessageFirstLine,
16637
+ incompatibleTypeChangeCount: incompatibleTypeChangeLines.length
16597
16638
  });
16598
16639
  } else if (noLog) {
16599
16640
  Logger.error({
16600
16641
  msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25",
16601
16642
  errorKind: kind,
16602
- errorMessage: errMessage,
16603
- incompatibleTypeChangeCount,
16604
- incompatibleTypeChanges
16643
+ errorMessage: errorMessageFirstLine,
16644
+ incompatibleTypeChangeCount: incompatibleTypeChangeLines.length
16605
16645
  });
16606
16646
  } else {
16607
16647
  Logger.error({
16608
16648
  msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25",
16609
16649
  errorKind: kind,
16610
- errorMessage: errMessage,
16650
+ errorMessage: errorMessageFirstLine,
16611
16651
  err: error,
16612
- incompatibleTypeChangeCount,
16613
- incompatibleTypeChanges
16652
+ incompatibleTypeChangeCount: incompatibleTypeChangeLines.length
16614
16653
  });
16615
16654
  }
16655
+ if (!alreadyLogged && incompatibleTypeChangeLines.length > 0) {
16656
+ for (const line of incompatibleTypeChangeLines) {
16657
+ Logger.error({
16658
+ msg: "\u4E0D\u517C\u5BB9\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4",
16659
+ incompatibleTypeChangeLine: line
16660
+ }, { truncate: false });
16661
+ }
16662
+ }
16616
16663
  try {
16617
16664
  await Logger.flush();
16618
16665
  } catch {}