@rawnodes/logger 2.6.0 → 2.7.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/dist/index.d.mts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +137 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +137 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -1
package/dist/index.mjs
CHANGED
|
@@ -1141,6 +1141,129 @@ function registerShutdown(logger, options = {}) {
|
|
|
1141
1141
|
return shutdown;
|
|
1142
1142
|
}
|
|
1143
1143
|
|
|
1144
|
+
// src/utils/error.ts
|
|
1145
|
+
function isAxiosError(error) {
|
|
1146
|
+
return error !== null && typeof error === "object" && "isAxiosError" in error && error.isAxiosError === true;
|
|
1147
|
+
}
|
|
1148
|
+
function sanitizeResponseData(data, maxStringLength = 1e4) {
|
|
1149
|
+
if (data === null || data === void 0) {
|
|
1150
|
+
return data;
|
|
1151
|
+
}
|
|
1152
|
+
if (typeof data === "string") {
|
|
1153
|
+
return data.length > maxStringLength ? `${data.slice(0, maxStringLength)}...[truncated]` : data;
|
|
1154
|
+
}
|
|
1155
|
+
if (typeof data === "number" || typeof data === "boolean") {
|
|
1156
|
+
return data;
|
|
1157
|
+
}
|
|
1158
|
+
if (Array.isArray(data)) {
|
|
1159
|
+
return data.slice(0, 100).map((item) => sanitizeResponseData(item, maxStringLength));
|
|
1160
|
+
}
|
|
1161
|
+
if (typeof data === "object") {
|
|
1162
|
+
const result = {};
|
|
1163
|
+
const entries = Object.entries(data);
|
|
1164
|
+
for (const [key, value] of entries.slice(0, 50)) {
|
|
1165
|
+
result[key] = sanitizeResponseData(value, maxStringLength);
|
|
1166
|
+
}
|
|
1167
|
+
return result;
|
|
1168
|
+
}
|
|
1169
|
+
return String(data);
|
|
1170
|
+
}
|
|
1171
|
+
function extractAxiosHttpData(error) {
|
|
1172
|
+
const httpData = {};
|
|
1173
|
+
if (error.code) {
|
|
1174
|
+
httpData.code = error.code;
|
|
1175
|
+
}
|
|
1176
|
+
if (error.response) {
|
|
1177
|
+
httpData.status = error.response.status;
|
|
1178
|
+
httpData.statusText = error.response.statusText;
|
|
1179
|
+
if (error.response.data !== void 0) {
|
|
1180
|
+
httpData.responseData = sanitizeResponseData(error.response.data);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (error.config) {
|
|
1184
|
+
const { url, baseURL, method } = error.config;
|
|
1185
|
+
if (url) {
|
|
1186
|
+
httpData.url = baseURL && !url.startsWith("http") ? `${baseURL}${url}` : url;
|
|
1187
|
+
}
|
|
1188
|
+
if (method) {
|
|
1189
|
+
httpData.method = method.toUpperCase();
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return httpData;
|
|
1193
|
+
}
|
|
1194
|
+
function extractGenericHttpData(error) {
|
|
1195
|
+
const httpData = {};
|
|
1196
|
+
let hasData = false;
|
|
1197
|
+
if (typeof error.code === "string") {
|
|
1198
|
+
httpData.code = error.code;
|
|
1199
|
+
hasData = true;
|
|
1200
|
+
}
|
|
1201
|
+
const response = error.response;
|
|
1202
|
+
if (response && typeof response === "object") {
|
|
1203
|
+
if (typeof response.status === "number") {
|
|
1204
|
+
httpData.status = response.status;
|
|
1205
|
+
hasData = true;
|
|
1206
|
+
}
|
|
1207
|
+
if (typeof response.statusText === "string") {
|
|
1208
|
+
httpData.statusText = response.statusText;
|
|
1209
|
+
hasData = true;
|
|
1210
|
+
}
|
|
1211
|
+
if (response.data !== void 0) {
|
|
1212
|
+
httpData.responseData = sanitizeResponseData(response.data);
|
|
1213
|
+
hasData = true;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
const config = error.config;
|
|
1217
|
+
if (config && typeof config === "object") {
|
|
1218
|
+
const url = config.url;
|
|
1219
|
+
const baseURL = config.baseURL;
|
|
1220
|
+
if (typeof url === "string") {
|
|
1221
|
+
httpData.url = baseURL && !url.startsWith("http") ? `${baseURL}${url}` : url;
|
|
1222
|
+
hasData = true;
|
|
1223
|
+
}
|
|
1224
|
+
if (typeof config.method === "string") {
|
|
1225
|
+
httpData.method = config.method.toUpperCase();
|
|
1226
|
+
hasData = true;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
return hasData ? httpData : void 0;
|
|
1230
|
+
}
|
|
1231
|
+
function serializeError(error) {
|
|
1232
|
+
if (!(error instanceof Error)) {
|
|
1233
|
+
if (error === null || error === void 0) {
|
|
1234
|
+
return { errorMessage: "Unknown error" };
|
|
1235
|
+
}
|
|
1236
|
+
if (typeof error === "string") {
|
|
1237
|
+
return { errorMessage: error };
|
|
1238
|
+
}
|
|
1239
|
+
const httpData2 = typeof error === "object" ? extractGenericHttpData(error) : void 0;
|
|
1240
|
+
return {
|
|
1241
|
+
errorMessage: String(error),
|
|
1242
|
+
http: httpData2
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
const serialized = {
|
|
1246
|
+
errorMessage: error.message,
|
|
1247
|
+
stack: error.stack
|
|
1248
|
+
};
|
|
1249
|
+
if (error.name && error.name !== "Error") {
|
|
1250
|
+
serialized.errorName = error.name;
|
|
1251
|
+
}
|
|
1252
|
+
if (isAxiosError(error)) {
|
|
1253
|
+
serialized.http = extractAxiosHttpData(error);
|
|
1254
|
+
return serialized;
|
|
1255
|
+
}
|
|
1256
|
+
const errWithCode = error;
|
|
1257
|
+
if (typeof errWithCode.code === "string") {
|
|
1258
|
+
serialized.code = errWithCode.code;
|
|
1259
|
+
}
|
|
1260
|
+
const httpData = extractGenericHttpData(error);
|
|
1261
|
+
if (httpData) {
|
|
1262
|
+
serialized.http = httpData;
|
|
1263
|
+
}
|
|
1264
|
+
return serialized;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1144
1267
|
// src/logger.ts
|
|
1145
1268
|
var Logger = class _Logger {
|
|
1146
1269
|
constructor(state, context) {
|
|
@@ -1269,11 +1392,19 @@ var Logger = class _Logger {
|
|
|
1269
1392
|
logMeta.caller = formatCallerInfo(callerInfo);
|
|
1270
1393
|
}
|
|
1271
1394
|
}
|
|
1272
|
-
if (error
|
|
1273
|
-
|
|
1274
|
-
logMeta.
|
|
1275
|
-
|
|
1276
|
-
|
|
1395
|
+
if (error !== void 0) {
|
|
1396
|
+
const serialized = serializeError(error);
|
|
1397
|
+
logMeta.errorMessage = serialized.errorMessage;
|
|
1398
|
+
logMeta.stack = serialized.stack;
|
|
1399
|
+
if (serialized.errorName) {
|
|
1400
|
+
logMeta.errorName = serialized.errorName;
|
|
1401
|
+
}
|
|
1402
|
+
if (serialized.code) {
|
|
1403
|
+
logMeta.errorCode = serialized.code;
|
|
1404
|
+
}
|
|
1405
|
+
if (serialized.http) {
|
|
1406
|
+
logMeta.http = serialized.http;
|
|
1407
|
+
}
|
|
1277
1408
|
}
|
|
1278
1409
|
const pinoMethod = this.getPinoMethod(level);
|
|
1279
1410
|
pinoMethod.call(this.state.pino, logMeta, message);
|
|
@@ -1523,6 +1654,6 @@ function formatLogfmt(data) {
|
|
|
1523
1654
|
return Object.entries(flattened).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${formatLogfmtValue(value)}`).join(" ");
|
|
1524
1655
|
}
|
|
1525
1656
|
|
|
1526
|
-
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, TelegramConfigSchema, TelegramTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, validateConfig };
|
|
1657
|
+
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, TelegramConfigSchema, TelegramTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
|
|
1527
1658
|
//# sourceMappingURL=index.mjs.map
|
|
1528
1659
|
//# sourceMappingURL=index.mjs.map
|