befly 3.12.1 → 3.12.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.
- package/dist/befly.js +13 -64
- package/dist/befly.min.js +12 -12
- package/dist/index.js +22 -25
- package/dist/lib/logger.js +3 -58
- package/package.json +2 -2
package/dist/befly.js
CHANGED
|
@@ -232,44 +232,6 @@ import { isAbsolute as nodePathIsAbsolute, join as nodePathJoin, resolve as node
|
|
|
232
232
|
function escapeRegExp(input) {
|
|
233
233
|
return String(input).replace(REGEXP_SPECIAL, "\\$&");
|
|
234
234
|
}
|
|
235
|
-
function installGracefulExitHooks() {
|
|
236
|
-
if (didInstallGracefulExitHooks)
|
|
237
|
-
return;
|
|
238
|
-
didInstallGracefulExitHooks = true;
|
|
239
|
-
const install = (signal, exitCode) => {
|
|
240
|
-
try {
|
|
241
|
-
if (typeof process.listenerCount === "function" && process.listenerCount(signal) > 0) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
} catch {}
|
|
245
|
-
try {
|
|
246
|
-
process.once(signal, () => {
|
|
247
|
-
let exited = false;
|
|
248
|
-
const timer = setTimeout(() => {
|
|
249
|
-
if (exited)
|
|
250
|
-
return;
|
|
251
|
-
exited = true;
|
|
252
|
-
try {
|
|
253
|
-
process.exit(exitCode);
|
|
254
|
-
} catch {}
|
|
255
|
-
}, 2000);
|
|
256
|
-
shutdown().catch(() => {
|
|
257
|
-
return;
|
|
258
|
-
}).finally(() => {
|
|
259
|
-
if (exited)
|
|
260
|
-
return;
|
|
261
|
-
exited = true;
|
|
262
|
-
clearTimeout(timer);
|
|
263
|
-
try {
|
|
264
|
-
process.exit(exitCode);
|
|
265
|
-
} catch {}
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
} catch {}
|
|
269
|
-
};
|
|
270
|
-
install("SIGINT", 130);
|
|
271
|
-
install("SIGTERM", 143);
|
|
272
|
-
}
|
|
273
235
|
function formatLocalDate(date) {
|
|
274
236
|
const y = date.getFullYear();
|
|
275
237
|
const m = date.getMonth() + 1;
|
|
@@ -598,6 +560,7 @@ async function shutdown() {
|
|
|
598
560
|
appConsoleSink = null;
|
|
599
561
|
instance = null;
|
|
600
562
|
errorInstance = null;
|
|
563
|
+
didEnsureLogDir = false;
|
|
601
564
|
}
|
|
602
565
|
function normalizePositiveInt(value, fallback, min, max) {
|
|
603
566
|
if (typeof value !== "number")
|
|
@@ -619,9 +582,6 @@ function resolveLogDir() {
|
|
|
619
582
|
return nodePathResolve(INITIAL_CWD, rawDir);
|
|
620
583
|
}
|
|
621
584
|
function ensureLogDirExists() {
|
|
622
|
-
if (didEnsureLogDir)
|
|
623
|
-
return;
|
|
624
|
-
didEnsureLogDir = true;
|
|
625
585
|
const dir = resolveLogDir();
|
|
626
586
|
try {
|
|
627
587
|
if (!existsSync2(dir)) {
|
|
@@ -630,6 +590,7 @@ function ensureLogDirExists() {
|
|
|
630
590
|
} catch (error) {
|
|
631
591
|
throw new Error(`\u521B\u5EFA logs \u76EE\u5F55\u5931\u8D25: ${dir}. ${error?.message || error}`);
|
|
632
592
|
}
|
|
593
|
+
didEnsureLogDir = true;
|
|
633
594
|
}
|
|
634
595
|
async function pruneOldLogFiles() {
|
|
635
596
|
if (didPruneOldLogFiles)
|
|
@@ -726,7 +687,6 @@ function getLogger() {
|
|
|
726
687
|
if (instance)
|
|
727
688
|
return instance;
|
|
728
689
|
ensureLogDirExists();
|
|
729
|
-
installGracefulExitHooks();
|
|
730
690
|
pruneOldLogFiles();
|
|
731
691
|
const minLevel = normalizeLogLevelName();
|
|
732
692
|
const maxFileBytes = (typeof config.maxSize === "number" && config.maxSize > 0 ? config.maxSize : 10) * 1024 * 1024;
|
|
@@ -745,7 +705,6 @@ function getErrorLogger() {
|
|
|
745
705
|
if (errorInstance)
|
|
746
706
|
return errorInstance;
|
|
747
707
|
ensureLogDirExists();
|
|
748
|
-
installGracefulExitHooks();
|
|
749
708
|
pruneOldLogFiles();
|
|
750
709
|
const maxFileBytes = (typeof config.maxSize === "number" && config.maxSize > 0 ? config.maxSize : 10) * 1024 * 1024;
|
|
751
710
|
if (!errorFileSink) {
|
|
@@ -1144,7 +1103,7 @@ function withRequestMeta(args) {
|
|
|
1144
1103
|
function withRequestMetaTyped(args) {
|
|
1145
1104
|
return withRequestMeta(args);
|
|
1146
1105
|
}
|
|
1147
|
-
var REGEXP_SPECIAL, INITIAL_CWD, DEFAULT_LOG_STRING_LEN = 100, DEFAULT_LOG_ARRAY_ITEMS = 100, maxLogStringLen, maxLogArrayItems, DEFAULT_LOG_SANITIZE_DEPTH = 3, DEFAULT_LOG_OBJECT_KEYS = 100, DEFAULT_LOG_SANITIZE_NODES = 500, sanitizeDepthLimit, sanitizeObjectKeysLimit, sanitizeNodesLimit, ONE_YEAR_MS, BUILTIN_SENSITIVE_KEYS, sensitiveKeySet, sensitiveContainsMatchers, sensitiveContainsRegex = null, HOSTNAME, LOG_LEVEL_NUM, DEFAULT_MAX_BUFFER_BYTES, DEFAULT_FLUSH_DELAY_MS = 10, DEFAULT_MAX_BATCH_BYTES, instance = null, errorInstance = null, mockInstance = null, appFileSink = null, errorFileSink = null, appConsoleSink = null, didWarnIoError = false, didPruneOldLogFiles = false, didEnsureLogDir = false,
|
|
1106
|
+
var REGEXP_SPECIAL, INITIAL_CWD, DEFAULT_LOG_STRING_LEN = 100, DEFAULT_LOG_ARRAY_ITEMS = 100, maxLogStringLen, maxLogArrayItems, DEFAULT_LOG_SANITIZE_DEPTH = 3, DEFAULT_LOG_OBJECT_KEYS = 100, DEFAULT_LOG_SANITIZE_NODES = 500, sanitizeDepthLimit, sanitizeObjectKeysLimit, sanitizeNodesLimit, ONE_YEAR_MS, BUILTIN_SENSITIVE_KEYS, sensitiveKeySet, sensitiveContainsMatchers, sensitiveContainsRegex = null, HOSTNAME, LOG_LEVEL_NUM, DEFAULT_MAX_BUFFER_BYTES, DEFAULT_FLUSH_DELAY_MS = 10, DEFAULT_MAX_BATCH_BYTES, instance = null, errorInstance = null, mockInstance = null, appFileSink = null, errorFileSink = null, appConsoleSink = null, didWarnIoError = false, didPruneOldLogFiles = false, didEnsureLogDir = false, config, Logger;
|
|
1148
1107
|
var init_logger = __esm(() => {
|
|
1149
1108
|
init_asyncContext();
|
|
1150
1109
|
REGEXP_SPECIAL = /[\\^$.*+?()[\]{}|]/g;
|
|
@@ -15590,29 +15549,19 @@ class Befly {
|
|
|
15590
15549
|
Logger.info(`${this.config.appName} \u542F\u52A8\u6210\u529F! (${roleLabel}${envLabel})`);
|
|
15591
15550
|
Logger.info(`\u670D\u52A1\u5668\u542F\u52A8\u8017\u65F6: ${finalStartupTime}`);
|
|
15592
15551
|
Logger.info(`\u670D\u52A1\u5668\u76D1\u542C\u5730\u5740: ${server.url}`);
|
|
15593
|
-
const gracefulShutdown = async (signal) => {
|
|
15594
|
-
Logger.info(`\u6536\u5230 ${signal} \u4FE1\u53F7\uFF0C\u5F00\u59CB\u4F18\u96C5\u5173\u95ED...`);
|
|
15595
|
-
try {
|
|
15596
|
-
await server.stop();
|
|
15597
|
-
Logger.info("HTTP \u670D\u52A1\u5668\u5DF2\u505C\u6B62");
|
|
15598
|
-
} catch (error) {
|
|
15599
|
-
Logger.error({ err: error }, "\u505C\u6B62 HTTP \u670D\u52A1\u5668\u65F6\u51FA\u9519");
|
|
15600
|
-
}
|
|
15601
|
-
try {
|
|
15602
|
-
await Connect.disconnect();
|
|
15603
|
-
Logger.info("\u6570\u636E\u5E93\u8FDE\u63A5\u5DF2\u5173\u95ED");
|
|
15604
|
-
} catch (error) {
|
|
15605
|
-
Logger.error({ err: error }, "\u5173\u95ED\u6570\u636E\u5E93\u8FDE\u63A5\u65F6\u51FA\u9519");
|
|
15606
|
-
}
|
|
15607
|
-
Logger.info("\u670D\u52A1\u5668\u5DF2\u4F18\u96C5\u5173\u95ED");
|
|
15608
|
-
process.exit(0);
|
|
15609
|
-
};
|
|
15610
|
-
process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
|
|
15611
|
-
process.on("SIGINT", () => gracefulShutdown("SIGINT"));
|
|
15612
15552
|
return server;
|
|
15613
15553
|
} catch (error) {
|
|
15614
15554
|
Logger.error({ err: error }, "\u9879\u76EE\u542F\u52A8\u5931\u8D25");
|
|
15615
|
-
|
|
15555
|
+
try {
|
|
15556
|
+
await Logger.flush();
|
|
15557
|
+
} catch {}
|
|
15558
|
+
try {
|
|
15559
|
+
await Logger.shutdown();
|
|
15560
|
+
} catch {}
|
|
15561
|
+
if (error instanceof Error) {
|
|
15562
|
+
throw error;
|
|
15563
|
+
}
|
|
15564
|
+
throw new Error(String(error));
|
|
15616
15565
|
}
|
|
15617
15566
|
}
|
|
15618
15567
|
}
|