@lark-apaas/nestjs-logger 0.1.0-alpha.1 → 0.1.0-alpha.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/index.cjs +14 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -73
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -14530,13 +14530,11 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14530
14530
|
const traceId = requestState?.requestId ?? null;
|
|
14531
14531
|
const payload = {
|
|
14532
14532
|
trace_id: traceId,
|
|
14533
|
-
requestId: traceId,
|
|
14534
14533
|
path: requestState?.path,
|
|
14535
14534
|
method: requestState?.method,
|
|
14536
14535
|
user_id: requestState?.userId ?? null,
|
|
14537
14536
|
app_id: requestState?.appId ?? null,
|
|
14538
14537
|
tenant_id: requestState?.tenantId ?? null,
|
|
14539
|
-
ip: requestState?.ip ?? null,
|
|
14540
14538
|
pid: process.pid
|
|
14541
14539
|
};
|
|
14542
14540
|
if (context) {
|
|
@@ -14703,44 +14701,11 @@ function normalizeLevel(level) {
|
|
|
14703
14701
|
}
|
|
14704
14702
|
}
|
|
14705
14703
|
__name(normalizeLevel, "normalizeLevel");
|
|
14706
|
-
function parseDestinations(raw) {
|
|
14707
|
-
if (!raw) {
|
|
14708
|
-
return [
|
|
14709
|
-
{
|
|
14710
|
-
type: "stdout"
|
|
14711
|
-
}
|
|
14712
|
-
];
|
|
14713
|
-
}
|
|
14714
|
-
return raw.split(",").map((token) => token.trim()).filter(Boolean).map((token) => {
|
|
14715
|
-
const [typeAndPath, level] = token.split("@");
|
|
14716
|
-
const [type, path] = typeAndPath.split(":");
|
|
14717
|
-
const normalizedType = (type ?? "stdout").toLowerCase();
|
|
14718
|
-
if (normalizedType === "file") {
|
|
14719
|
-
return {
|
|
14720
|
-
type: "file",
|
|
14721
|
-
path: path || "logs/app.log",
|
|
14722
|
-
level
|
|
14723
|
-
};
|
|
14724
|
-
}
|
|
14725
|
-
if (normalizedType === "stderr") {
|
|
14726
|
-
return {
|
|
14727
|
-
type: "stderr",
|
|
14728
|
-
level
|
|
14729
|
-
};
|
|
14730
|
-
}
|
|
14731
|
-
return {
|
|
14732
|
-
type: "stdout",
|
|
14733
|
-
level
|
|
14734
|
-
};
|
|
14735
|
-
});
|
|
14736
|
-
}
|
|
14737
|
-
__name(parseDestinations, "parseDestinations");
|
|
14738
14704
|
var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
14739
14705
|
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "info" : "debug"));
|
|
14740
|
-
const destinations = parseDestinations(process.env.LOGGER_DESTINATIONS);
|
|
14741
14706
|
return {
|
|
14742
14707
|
level,
|
|
14743
|
-
|
|
14708
|
+
logDir: process.env.LOG_DIR || "logs"
|
|
14744
14709
|
};
|
|
14745
14710
|
});
|
|
14746
14711
|
|
|
@@ -14854,12 +14819,12 @@ function createPinoLogger(config) {
|
|
|
14854
14819
|
}
|
|
14855
14820
|
}
|
|
14856
14821
|
};
|
|
14857
|
-
const
|
|
14822
|
+
const streams = [
|
|
14858
14823
|
{
|
|
14859
|
-
|
|
14824
|
+
level: config.level,
|
|
14825
|
+
stream: createFileDestination(config.filePath)
|
|
14860
14826
|
}
|
|
14861
14827
|
];
|
|
14862
|
-
const streams = buildStreams(destinations, baseLevel);
|
|
14863
14828
|
if (streams.length === 0) {
|
|
14864
14829
|
return (0, import_pino.default)(options);
|
|
14865
14830
|
}
|
|
@@ -14869,30 +14834,6 @@ function createPinoLogger(config) {
|
|
|
14869
14834
|
return (0, import_pino.default)(options, import_pino.default.multistream(streams));
|
|
14870
14835
|
}
|
|
14871
14836
|
__name(createPinoLogger, "createPinoLogger");
|
|
14872
|
-
function buildStreams(destinations, fallbackLevel) {
|
|
14873
|
-
return destinations.map((destination) => {
|
|
14874
|
-
const level = normalizeLevel(destination.level ?? fallbackLevel);
|
|
14875
|
-
switch (destination.type) {
|
|
14876
|
-
case "stderr":
|
|
14877
|
-
return {
|
|
14878
|
-
level,
|
|
14879
|
-
stream: process.stderr
|
|
14880
|
-
};
|
|
14881
|
-
case "file":
|
|
14882
|
-
return {
|
|
14883
|
-
level,
|
|
14884
|
-
stream: createFileDestination(destination.path)
|
|
14885
|
-
};
|
|
14886
|
-
case "stdout":
|
|
14887
|
-
default:
|
|
14888
|
-
return {
|
|
14889
|
-
level,
|
|
14890
|
-
stream: process.stdout
|
|
14891
|
-
};
|
|
14892
|
-
}
|
|
14893
|
-
});
|
|
14894
|
-
}
|
|
14895
|
-
__name(buildStreams, "buildStreams");
|
|
14896
14837
|
function createFileDestination(pathname) {
|
|
14897
14838
|
const target = pathname && pathname.length > 0 ? pathname : "logs/app.log";
|
|
14898
14839
|
const resolved = (0, import_path.isAbsolute)(target) ? target : (0, import_path.join)(process.cwd(), target);
|
|
@@ -14980,25 +14921,25 @@ LoggerModule = _ts_decorate5([
|
|
|
14980
14921
|
LoggerContextMiddleware,
|
|
14981
14922
|
{
|
|
14982
14923
|
provide: PINO_ROOT_LOGGER,
|
|
14983
|
-
useFactory: /* @__PURE__ */ __name((config) =>
|
|
14924
|
+
useFactory: /* @__PURE__ */ __name((config) => {
|
|
14925
|
+
return createPinoLogger({
|
|
14926
|
+
level: "trace",
|
|
14927
|
+
filePath: `${config.logDir}/app.log`
|
|
14928
|
+
});
|
|
14929
|
+
}, "useFactory"),
|
|
14984
14930
|
inject: [
|
|
14985
14931
|
logger_config_default.KEY
|
|
14986
14932
|
]
|
|
14987
14933
|
},
|
|
14988
14934
|
{
|
|
14989
14935
|
provide: TRACE_LOGGER,
|
|
14990
|
-
useFactory: /* @__PURE__ */ __name((requestContext) => new PinoLoggerService(createPinoLogger({
|
|
14936
|
+
useFactory: /* @__PURE__ */ __name((requestContext, config) => new PinoLoggerService(createPinoLogger({
|
|
14991
14937
|
level: "trace",
|
|
14992
|
-
|
|
14993
|
-
{
|
|
14994
|
-
type: "file",
|
|
14995
|
-
path: "logs/trace.log",
|
|
14996
|
-
level: "trace"
|
|
14997
|
-
}
|
|
14998
|
-
]
|
|
14938
|
+
filePath: `${config.logDir}/trace.log`
|
|
14999
14939
|
}), requestContext), "useFactory"),
|
|
15000
14940
|
inject: [
|
|
15001
|
-
RequestContextService
|
|
14941
|
+
RequestContextService,
|
|
14942
|
+
logger_config_default.KEY
|
|
15002
14943
|
]
|
|
15003
14944
|
},
|
|
15004
14945
|
AppLogger,
|