unnbound-logger-sdk 1.1.2 → 1.1.5
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/unnbound-logger.js +56 -31
- package/package.json +1 -1
package/dist/unnbound-logger.js
CHANGED
|
@@ -61,15 +61,18 @@ class UnnboundLogger {
|
|
|
61
61
|
}
|
|
62
62
|
// Store request start time for duration calculation
|
|
63
63
|
config.metadata = { startTime: Date.now() };
|
|
64
|
-
// Log the outgoing request
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
// Log the outgoing request using proper httpRequest method
|
|
65
|
+
const mockReq = {
|
|
66
|
+
method: config.method?.toUpperCase() || 'UNKNOWN',
|
|
67
|
+
url: `${config.baseURL || ''}${config.url}`,
|
|
68
|
+
originalUrl: `${config.baseURL || ''}${config.url}`,
|
|
69
|
+
headers: config.headers || {},
|
|
70
|
+
body: config.data,
|
|
71
|
+
ip: 'outgoing' // Mark as outgoing request
|
|
72
|
+
};
|
|
73
|
+
this.httpRequest(mockReq, {
|
|
74
|
+
traceId,
|
|
75
|
+
startTime: config.metadata.startTime
|
|
73
76
|
});
|
|
74
77
|
return config;
|
|
75
78
|
},
|
|
@@ -83,17 +86,25 @@ class UnnboundLogger {
|
|
|
83
86
|
// Calculate duration
|
|
84
87
|
const startTime = response.config.metadata?.startTime || Date.now();
|
|
85
88
|
const duration = Date.now() - startTime;
|
|
86
|
-
// Log the successful response
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
// Log the successful response using proper httpResponse method
|
|
90
|
+
const mockReq = {
|
|
91
|
+
method: response.config.method?.toUpperCase() || 'UNKNOWN',
|
|
92
|
+
url: `${response.config.baseURL || ''}${response.config.url}`,
|
|
93
|
+
originalUrl: `${response.config.baseURL || ''}${response.config.url}`,
|
|
94
|
+
ip: 'outgoing' // Mark as outgoing request
|
|
95
|
+
};
|
|
96
|
+
const mockRes = {
|
|
97
|
+
statusCode: response.status,
|
|
98
|
+
locals: {
|
|
99
|
+
body: response.data,
|
|
100
|
+
startTime: startTime,
|
|
101
|
+
traceId: trace_context_1.traceContext.getTraceId()
|
|
102
|
+
},
|
|
103
|
+
getHeaders: () => response.headers || {}
|
|
104
|
+
};
|
|
105
|
+
this.httpResponse(mockRes, mockReq, {
|
|
89
106
|
duration,
|
|
90
|
-
|
|
91
|
-
url: `${response.config.baseURL || ''}${response.config.url}`,
|
|
92
|
-
method: response.config.method?.toUpperCase(),
|
|
93
|
-
status: response.status,
|
|
94
|
-
headers: (0, logger_utils_1.filterHeaders)(response.headers),
|
|
95
|
-
body: response.data
|
|
96
|
-
}
|
|
107
|
+
traceId: trace_context_1.traceContext.getTraceId()
|
|
97
108
|
});
|
|
98
109
|
return response;
|
|
99
110
|
},
|
|
@@ -101,21 +112,30 @@ class UnnboundLogger {
|
|
|
101
112
|
// Calculate duration for error responses
|
|
102
113
|
const startTime = error.config?.metadata?.startTime || Date.now();
|
|
103
114
|
const duration = Date.now() - startTime;
|
|
104
|
-
// Log the error response
|
|
115
|
+
// Log the error response using proper httpResponse method
|
|
105
116
|
if (error.response) {
|
|
106
|
-
|
|
107
|
-
|
|
117
|
+
const mockReq = {
|
|
118
|
+
method: error.config?.method?.toUpperCase() || 'UNKNOWN',
|
|
119
|
+
url: `${error.config?.baseURL || ''}${error.config?.url}`,
|
|
120
|
+
originalUrl: `${error.config?.baseURL || ''}${error.config?.url}`,
|
|
121
|
+
ip: 'outgoing' // Mark as outgoing request
|
|
122
|
+
};
|
|
123
|
+
const mockRes = {
|
|
124
|
+
statusCode: error.response.status,
|
|
125
|
+
locals: {
|
|
126
|
+
body: error.response.data,
|
|
127
|
+
startTime: startTime,
|
|
128
|
+
traceId: trace_context_1.traceContext.getTraceId()
|
|
129
|
+
},
|
|
130
|
+
getHeaders: () => error.response.headers || {}
|
|
131
|
+
};
|
|
132
|
+
this.httpResponse(mockRes, mockReq, {
|
|
108
133
|
duration,
|
|
109
|
-
|
|
110
|
-
url: `${error.config?.baseURL || ''}${error.config?.url}`,
|
|
111
|
-
method: error.config?.method?.toUpperCase(),
|
|
112
|
-
status: error.response.status,
|
|
113
|
-
headers: (0, logger_utils_1.filterHeaders)(error.response.headers),
|
|
114
|
-
body: error.response.data
|
|
115
|
-
}
|
|
134
|
+
traceId: trace_context_1.traceContext.getTraceId()
|
|
116
135
|
});
|
|
117
136
|
}
|
|
118
137
|
else {
|
|
138
|
+
// For network errors without response, log as general error
|
|
119
139
|
this.error(`HTTP Request Failed: ${error.config?.method?.toUpperCase()} ${error.config?.baseURL || ''}${error.config?.url}`, {
|
|
120
140
|
context: 'No response received',
|
|
121
141
|
error: error.message
|
|
@@ -138,6 +158,11 @@ class UnnboundLogger {
|
|
|
138
158
|
...(this.environment && { environment: this.environment }),
|
|
139
159
|
},
|
|
140
160
|
timestamp: () => `,"timestamp":"${new Date().toISOString()}"`,
|
|
161
|
+
formatters: {
|
|
162
|
+
level: (label) => {
|
|
163
|
+
return { level: label };
|
|
164
|
+
},
|
|
165
|
+
},
|
|
141
166
|
});
|
|
142
167
|
}
|
|
143
168
|
/**
|
|
@@ -259,7 +284,7 @@ class UnnboundLogger {
|
|
|
259
284
|
url: req.originalUrl || req.url,
|
|
260
285
|
method: req.method,
|
|
261
286
|
headers: (0, logger_utils_1.filterHeaders)(req.headers),
|
|
262
|
-
ip: req.ip,
|
|
287
|
+
ip: (0, logger_utils_1.normalizeIp)(req.ip),
|
|
263
288
|
body: req.body,
|
|
264
289
|
},
|
|
265
290
|
};
|
|
@@ -300,7 +325,7 @@ class UnnboundLogger {
|
|
|
300
325
|
url: req.originalUrl || req.url,
|
|
301
326
|
method: req.method,
|
|
302
327
|
headers: (0, logger_utils_1.filterHeaders)(res.getHeaders()),
|
|
303
|
-
ip: req.ip,
|
|
328
|
+
ip: (0, logger_utils_1.normalizeIp)(req.ip),
|
|
304
329
|
status: res.statusCode,
|
|
305
330
|
body: res.locals.body,
|
|
306
331
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unnbound-logger-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging across different operational contexts with automatic trace ID propagation.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|