@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.d.mts
CHANGED
|
@@ -336,6 +336,54 @@ interface GracefulShutdownOptions {
|
|
|
336
336
|
*/
|
|
337
337
|
declare function registerShutdown<TContext extends LoggerContext>(logger: Logger<TContext>, options?: GracefulShutdownOptions): () => Promise<void>;
|
|
338
338
|
|
|
339
|
+
/**
|
|
340
|
+
* HTTP error data extracted from axios/fetch errors
|
|
341
|
+
*/
|
|
342
|
+
interface HttpErrorData {
|
|
343
|
+
/** HTTP status code (e.g., 400, 500) */
|
|
344
|
+
status?: number;
|
|
345
|
+
/** HTTP status text (e.g., "Bad Request") */
|
|
346
|
+
statusText?: string;
|
|
347
|
+
/** Response body data */
|
|
348
|
+
responseData?: unknown;
|
|
349
|
+
/** Request URL */
|
|
350
|
+
url?: string;
|
|
351
|
+
/** HTTP method (GET, POST, etc.) */
|
|
352
|
+
method?: string;
|
|
353
|
+
/** Error code (e.g., ECONNREFUSED, ETIMEDOUT) */
|
|
354
|
+
code?: string;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Serialized error data for logging
|
|
358
|
+
*/
|
|
359
|
+
interface SerializedError {
|
|
360
|
+
/** Error message */
|
|
361
|
+
errorMessage: string;
|
|
362
|
+
/** Stack trace */
|
|
363
|
+
stack?: string;
|
|
364
|
+
/** HTTP-specific data if present */
|
|
365
|
+
http?: HttpErrorData;
|
|
366
|
+
/** Error code for non-HTTP errors */
|
|
367
|
+
code?: string;
|
|
368
|
+
/** Error name/type */
|
|
369
|
+
errorName?: string;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Serializes an Error object for logging, extracting HTTP-specific data
|
|
373
|
+
* from axios/fetch errors while preserving standard error properties.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* // Axios error
|
|
377
|
+
* try {
|
|
378
|
+
* await axios.get('/api/data');
|
|
379
|
+
* } catch (error) {
|
|
380
|
+
* const serialized = serializeError(error);
|
|
381
|
+
* // serialized.http.status = 400
|
|
382
|
+
* // serialized.http.responseData = { error: "invalid input" }
|
|
383
|
+
* }
|
|
384
|
+
*/
|
|
385
|
+
declare function serializeError(error: unknown): SerializedError;
|
|
386
|
+
|
|
339
387
|
declare function flattenObject(obj: Record<string, unknown>, prefix?: string, ancestors?: WeakSet<object>, depth?: number): Record<string, unknown>;
|
|
340
388
|
declare function formatLogfmtValue(value: unknown): string;
|
|
341
389
|
declare function formatLogfmt(data: Record<string, unknown>): string;
|
|
@@ -381,4 +429,4 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
|
|
|
381
429
|
autoShutdown?: boolean | AutoShutdownConfig | undefined;
|
|
382
430
|
}>;
|
|
383
431
|
|
|
384
|
-
export { type AutoShutdownConfig, AutoShutdownConfigSchema, BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type GracefulShutdownOptions, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, type LogStreamName, LogStreamNameSchema, type LogStreamPattern, type LogStreamPatternConfig, LogStreamPatternConfigSchema, LogStreamPatternSchema, type LogStreamTemplateConfig, LogStreamTemplateConfigSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, validateConfig };
|
|
432
|
+
export { type AutoShutdownConfig, AutoShutdownConfigSchema, BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type GracefulShutdownOptions, type HttpErrorData, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, type LogStreamName, LogStreamNameSchema, type LogStreamPattern, type LogStreamPatternConfig, LogStreamPatternConfigSchema, LogStreamPatternSchema, type LogStreamTemplateConfig, LogStreamTemplateConfigSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SerializedError, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -336,6 +336,54 @@ interface GracefulShutdownOptions {
|
|
|
336
336
|
*/
|
|
337
337
|
declare function registerShutdown<TContext extends LoggerContext>(logger: Logger<TContext>, options?: GracefulShutdownOptions): () => Promise<void>;
|
|
338
338
|
|
|
339
|
+
/**
|
|
340
|
+
* HTTP error data extracted from axios/fetch errors
|
|
341
|
+
*/
|
|
342
|
+
interface HttpErrorData {
|
|
343
|
+
/** HTTP status code (e.g., 400, 500) */
|
|
344
|
+
status?: number;
|
|
345
|
+
/** HTTP status text (e.g., "Bad Request") */
|
|
346
|
+
statusText?: string;
|
|
347
|
+
/** Response body data */
|
|
348
|
+
responseData?: unknown;
|
|
349
|
+
/** Request URL */
|
|
350
|
+
url?: string;
|
|
351
|
+
/** HTTP method (GET, POST, etc.) */
|
|
352
|
+
method?: string;
|
|
353
|
+
/** Error code (e.g., ECONNREFUSED, ETIMEDOUT) */
|
|
354
|
+
code?: string;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Serialized error data for logging
|
|
358
|
+
*/
|
|
359
|
+
interface SerializedError {
|
|
360
|
+
/** Error message */
|
|
361
|
+
errorMessage: string;
|
|
362
|
+
/** Stack trace */
|
|
363
|
+
stack?: string;
|
|
364
|
+
/** HTTP-specific data if present */
|
|
365
|
+
http?: HttpErrorData;
|
|
366
|
+
/** Error code for non-HTTP errors */
|
|
367
|
+
code?: string;
|
|
368
|
+
/** Error name/type */
|
|
369
|
+
errorName?: string;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Serializes an Error object for logging, extracting HTTP-specific data
|
|
373
|
+
* from axios/fetch errors while preserving standard error properties.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* // Axios error
|
|
377
|
+
* try {
|
|
378
|
+
* await axios.get('/api/data');
|
|
379
|
+
* } catch (error) {
|
|
380
|
+
* const serialized = serializeError(error);
|
|
381
|
+
* // serialized.http.status = 400
|
|
382
|
+
* // serialized.http.responseData = { error: "invalid input" }
|
|
383
|
+
* }
|
|
384
|
+
*/
|
|
385
|
+
declare function serializeError(error: unknown): SerializedError;
|
|
386
|
+
|
|
339
387
|
declare function flattenObject(obj: Record<string, unknown>, prefix?: string, ancestors?: WeakSet<object>, depth?: number): Record<string, unknown>;
|
|
340
388
|
declare function formatLogfmtValue(value: unknown): string;
|
|
341
389
|
declare function formatLogfmt(data: Record<string, unknown>): string;
|
|
@@ -381,4 +429,4 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
|
|
|
381
429
|
autoShutdown?: boolean | AutoShutdownConfig | undefined;
|
|
382
430
|
}>;
|
|
383
431
|
|
|
384
|
-
export { type AutoShutdownConfig, AutoShutdownConfigSchema, BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type GracefulShutdownOptions, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, type LogStreamName, LogStreamNameSchema, type LogStreamPattern, type LogStreamPatternConfig, LogStreamPatternConfigSchema, LogStreamPatternSchema, type LogStreamTemplateConfig, LogStreamTemplateConfigSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, validateConfig };
|
|
432
|
+
export { type AutoShutdownConfig, AutoShutdownConfigSchema, BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type GracefulShutdownOptions, type HttpErrorData, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, type LogStreamName, LogStreamNameSchema, type LogStreamPattern, type LogStreamPatternConfig, LogStreamPatternConfigSchema, LogStreamPatternSchema, type LogStreamTemplateConfig, LogStreamTemplateConfigSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SerializedError, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
|
package/dist/index.js
CHANGED
|
@@ -1147,6 +1147,129 @@ function registerShutdown(logger, options = {}) {
|
|
|
1147
1147
|
return shutdown;
|
|
1148
1148
|
}
|
|
1149
1149
|
|
|
1150
|
+
// src/utils/error.ts
|
|
1151
|
+
function isAxiosError(error) {
|
|
1152
|
+
return error !== null && typeof error === "object" && "isAxiosError" in error && error.isAxiosError === true;
|
|
1153
|
+
}
|
|
1154
|
+
function sanitizeResponseData(data, maxStringLength = 1e4) {
|
|
1155
|
+
if (data === null || data === void 0) {
|
|
1156
|
+
return data;
|
|
1157
|
+
}
|
|
1158
|
+
if (typeof data === "string") {
|
|
1159
|
+
return data.length > maxStringLength ? `${data.slice(0, maxStringLength)}...[truncated]` : data;
|
|
1160
|
+
}
|
|
1161
|
+
if (typeof data === "number" || typeof data === "boolean") {
|
|
1162
|
+
return data;
|
|
1163
|
+
}
|
|
1164
|
+
if (Array.isArray(data)) {
|
|
1165
|
+
return data.slice(0, 100).map((item) => sanitizeResponseData(item, maxStringLength));
|
|
1166
|
+
}
|
|
1167
|
+
if (typeof data === "object") {
|
|
1168
|
+
const result = {};
|
|
1169
|
+
const entries = Object.entries(data);
|
|
1170
|
+
for (const [key, value] of entries.slice(0, 50)) {
|
|
1171
|
+
result[key] = sanitizeResponseData(value, maxStringLength);
|
|
1172
|
+
}
|
|
1173
|
+
return result;
|
|
1174
|
+
}
|
|
1175
|
+
return String(data);
|
|
1176
|
+
}
|
|
1177
|
+
function extractAxiosHttpData(error) {
|
|
1178
|
+
const httpData = {};
|
|
1179
|
+
if (error.code) {
|
|
1180
|
+
httpData.code = error.code;
|
|
1181
|
+
}
|
|
1182
|
+
if (error.response) {
|
|
1183
|
+
httpData.status = error.response.status;
|
|
1184
|
+
httpData.statusText = error.response.statusText;
|
|
1185
|
+
if (error.response.data !== void 0) {
|
|
1186
|
+
httpData.responseData = sanitizeResponseData(error.response.data);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
if (error.config) {
|
|
1190
|
+
const { url, baseURL, method } = error.config;
|
|
1191
|
+
if (url) {
|
|
1192
|
+
httpData.url = baseURL && !url.startsWith("http") ? `${baseURL}${url}` : url;
|
|
1193
|
+
}
|
|
1194
|
+
if (method) {
|
|
1195
|
+
httpData.method = method.toUpperCase();
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
return httpData;
|
|
1199
|
+
}
|
|
1200
|
+
function extractGenericHttpData(error) {
|
|
1201
|
+
const httpData = {};
|
|
1202
|
+
let hasData = false;
|
|
1203
|
+
if (typeof error.code === "string") {
|
|
1204
|
+
httpData.code = error.code;
|
|
1205
|
+
hasData = true;
|
|
1206
|
+
}
|
|
1207
|
+
const response = error.response;
|
|
1208
|
+
if (response && typeof response === "object") {
|
|
1209
|
+
if (typeof response.status === "number") {
|
|
1210
|
+
httpData.status = response.status;
|
|
1211
|
+
hasData = true;
|
|
1212
|
+
}
|
|
1213
|
+
if (typeof response.statusText === "string") {
|
|
1214
|
+
httpData.statusText = response.statusText;
|
|
1215
|
+
hasData = true;
|
|
1216
|
+
}
|
|
1217
|
+
if (response.data !== void 0) {
|
|
1218
|
+
httpData.responseData = sanitizeResponseData(response.data);
|
|
1219
|
+
hasData = true;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
const config = error.config;
|
|
1223
|
+
if (config && typeof config === "object") {
|
|
1224
|
+
const url = config.url;
|
|
1225
|
+
const baseURL = config.baseURL;
|
|
1226
|
+
if (typeof url === "string") {
|
|
1227
|
+
httpData.url = baseURL && !url.startsWith("http") ? `${baseURL}${url}` : url;
|
|
1228
|
+
hasData = true;
|
|
1229
|
+
}
|
|
1230
|
+
if (typeof config.method === "string") {
|
|
1231
|
+
httpData.method = config.method.toUpperCase();
|
|
1232
|
+
hasData = true;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
return hasData ? httpData : void 0;
|
|
1236
|
+
}
|
|
1237
|
+
function serializeError(error) {
|
|
1238
|
+
if (!(error instanceof Error)) {
|
|
1239
|
+
if (error === null || error === void 0) {
|
|
1240
|
+
return { errorMessage: "Unknown error" };
|
|
1241
|
+
}
|
|
1242
|
+
if (typeof error === "string") {
|
|
1243
|
+
return { errorMessage: error };
|
|
1244
|
+
}
|
|
1245
|
+
const httpData2 = typeof error === "object" ? extractGenericHttpData(error) : void 0;
|
|
1246
|
+
return {
|
|
1247
|
+
errorMessage: String(error),
|
|
1248
|
+
http: httpData2
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
const serialized = {
|
|
1252
|
+
errorMessage: error.message,
|
|
1253
|
+
stack: error.stack
|
|
1254
|
+
};
|
|
1255
|
+
if (error.name && error.name !== "Error") {
|
|
1256
|
+
serialized.errorName = error.name;
|
|
1257
|
+
}
|
|
1258
|
+
if (isAxiosError(error)) {
|
|
1259
|
+
serialized.http = extractAxiosHttpData(error);
|
|
1260
|
+
return serialized;
|
|
1261
|
+
}
|
|
1262
|
+
const errWithCode = error;
|
|
1263
|
+
if (typeof errWithCode.code === "string") {
|
|
1264
|
+
serialized.code = errWithCode.code;
|
|
1265
|
+
}
|
|
1266
|
+
const httpData = extractGenericHttpData(error);
|
|
1267
|
+
if (httpData) {
|
|
1268
|
+
serialized.http = httpData;
|
|
1269
|
+
}
|
|
1270
|
+
return serialized;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1150
1273
|
// src/logger.ts
|
|
1151
1274
|
var Logger = class _Logger {
|
|
1152
1275
|
constructor(state, context) {
|
|
@@ -1275,11 +1398,19 @@ var Logger = class _Logger {
|
|
|
1275
1398
|
logMeta.caller = formatCallerInfo(callerInfo);
|
|
1276
1399
|
}
|
|
1277
1400
|
}
|
|
1278
|
-
if (error
|
|
1279
|
-
|
|
1280
|
-
logMeta.
|
|
1281
|
-
|
|
1282
|
-
|
|
1401
|
+
if (error !== void 0) {
|
|
1402
|
+
const serialized = serializeError(error);
|
|
1403
|
+
logMeta.errorMessage = serialized.errorMessage;
|
|
1404
|
+
logMeta.stack = serialized.stack;
|
|
1405
|
+
if (serialized.errorName) {
|
|
1406
|
+
logMeta.errorName = serialized.errorName;
|
|
1407
|
+
}
|
|
1408
|
+
if (serialized.code) {
|
|
1409
|
+
logMeta.errorCode = serialized.code;
|
|
1410
|
+
}
|
|
1411
|
+
if (serialized.http) {
|
|
1412
|
+
logMeta.http = serialized.http;
|
|
1413
|
+
}
|
|
1283
1414
|
}
|
|
1284
1415
|
const pinoMethod = this.getPinoMethod(level);
|
|
1285
1416
|
pinoMethod.call(this.state.pino, logMeta, message);
|
|
@@ -1573,6 +1704,7 @@ exports.measureAsync = measureAsync;
|
|
|
1573
1704
|
exports.measureSync = measureSync;
|
|
1574
1705
|
exports.registerShutdown = registerShutdown;
|
|
1575
1706
|
exports.safeValidateConfig = safeValidateConfig;
|
|
1707
|
+
exports.serializeError = serializeError;
|
|
1576
1708
|
exports.validateConfig = validateConfig;
|
|
1577
1709
|
//# sourceMappingURL=index.js.map
|
|
1578
1710
|
//# sourceMappingURL=index.js.map
|