@takeshape/logger 11.121.6 → 11.121.9
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/logger.d.ts +2 -1
- package/dist/logger.js +11 -10
- package/dist/types.d.ts +10 -15
- package/package.json +2 -2
package/dist/logger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type Sentry from '@sentry/
|
|
1
|
+
import type Sentry from '@sentry/core';
|
|
2
2
|
import type { LogContext, Logger, LogProvider } from './types.ts';
|
|
3
3
|
type JsonLog = {
|
|
4
4
|
[key: string]: unknown;
|
|
@@ -19,6 +19,7 @@ type LoggerOptions = {
|
|
|
19
19
|
provider: LogProvider;
|
|
20
20
|
level: string;
|
|
21
21
|
sentryClient?: Pick<Sentry.Client, 'captureException' | 'captureMessage'>;
|
|
22
|
+
messageOnly?: boolean;
|
|
22
23
|
};
|
|
23
24
|
export declare function createLogger({ level, ...options }: LoggerOptions, logContext?: LogContext): Logger;
|
|
24
25
|
export {};
|
package/dist/logger.js
CHANGED
|
@@ -24,7 +24,7 @@ function getFargateEmf(now, metadata) {
|
|
|
24
24
|
},
|
|
25
25
|
serviceName: metadata.context?.platform?.fargate?.service,
|
|
26
26
|
taskRevision: metadata.context?.platform?.fargate?.task_revision,
|
|
27
|
-
time: metadata.event?.
|
|
27
|
+
time: metadata.event?.duration
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function getLambdaEmf(now, metadata) {
|
|
@@ -46,7 +46,7 @@ function getLambdaEmf(now, metadata) {
|
|
|
46
46
|
]
|
|
47
47
|
},
|
|
48
48
|
functionVersion: '$LATEST',
|
|
49
|
-
time: metadata.event?.
|
|
49
|
+
time: metadata.event?.duration
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
@@ -54,7 +54,7 @@ function getLambdaEmf(now, metadata) {
|
|
|
54
54
|
*
|
|
55
55
|
* @link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html#nodejs-logging-advanced-JSON
|
|
56
56
|
*/
|
|
57
|
-
function getJsonLog({ level, message, metadata, requestId, error }, emfFn) {
|
|
57
|
+
function getJsonLog({ level, message, metadata, requestId, error, messageOnly }, emfFn) {
|
|
58
58
|
const now = metadata.timestamp ? new Date(metadata.timestamp).valueOf() : Date.now();
|
|
59
59
|
// https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html#nodejs-logging-advanced-level
|
|
60
60
|
let jsonLog = {
|
|
@@ -63,7 +63,7 @@ function getJsonLog({ level, message, metadata, requestId, error }, emfFn) {
|
|
|
63
63
|
level,
|
|
64
64
|
timestamp: new Date(now).toISOString(),
|
|
65
65
|
requestId,
|
|
66
|
-
...(!
|
|
66
|
+
...(!messageOnly ? metadata : undefined)
|
|
67
67
|
};
|
|
68
68
|
if (error) {
|
|
69
69
|
jsonLog = {
|
|
@@ -73,7 +73,7 @@ function getJsonLog({ level, message, metadata, requestId, error }, emfFn) {
|
|
|
73
73
|
stackTrace: error.stack
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
if (emfFn && metadata.event?.
|
|
76
|
+
if (emfFn && metadata.event?.duration) {
|
|
77
77
|
// https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html#nodejs-logging-advanced-emf
|
|
78
78
|
jsonLog = {
|
|
79
79
|
...jsonLog,
|
|
@@ -152,7 +152,7 @@ export function shouldReportToSentry(error) {
|
|
|
152
152
|
}
|
|
153
153
|
return true;
|
|
154
154
|
}
|
|
155
|
-
function decorateLogFn({ provider, level, sentryClient }, entry) {
|
|
155
|
+
function decorateLogFn({ provider, level, sentryClient, messageOnly }, entry) {
|
|
156
156
|
return (messageOrError, logMetadata) => {
|
|
157
157
|
let metadata = logMetadata;
|
|
158
158
|
let message;
|
|
@@ -215,11 +215,11 @@ function decorateLogFn({ provider, level, sentryClient }, entry) {
|
|
|
215
215
|
if (provider === 'CONSOLE') {
|
|
216
216
|
// biome-ignore lint/suspicious/noConsole: allowed
|
|
217
217
|
const consoleMethod = console[level.toLowerCase()];
|
|
218
|
-
if (!
|
|
219
|
-
consoleMethod(
|
|
218
|
+
if (!messageOnly) {
|
|
219
|
+
consoleMethod(...[message, error, metadata].filter((x) => x));
|
|
220
220
|
}
|
|
221
221
|
else {
|
|
222
|
-
consoleMethod(
|
|
222
|
+
consoleMethod(...[message, error].filter((x) => x));
|
|
223
223
|
}
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
@@ -228,7 +228,8 @@ function decorateLogFn({ provider, level, sentryClient }, entry) {
|
|
|
228
228
|
message,
|
|
229
229
|
metadata,
|
|
230
230
|
error,
|
|
231
|
-
requestId: metadata?.context?.http?.request_id
|
|
231
|
+
requestId: metadata?.context?.http?.request_id,
|
|
232
|
+
messageOnly
|
|
232
233
|
}, provider === 'CLOUDWATCH_LAMBDA' ? getLambdaEmf : getFargateEmf);
|
|
233
234
|
process.stdout.write(formatLogEntry(jsonLog, {
|
|
234
235
|
prefixMessage: provider === 'CLOUDWATCH_LAMBDA'
|
package/dist/types.d.ts
CHANGED
|
@@ -113,6 +113,7 @@ export type LogContext = {
|
|
|
113
113
|
path?: HttpPath;
|
|
114
114
|
remote_addr?: HttpRemoteAddr;
|
|
115
115
|
request_id?: HttpRequestId;
|
|
116
|
+
start_at?: TimeMs;
|
|
116
117
|
};
|
|
117
118
|
/**
|
|
118
119
|
* Represents a task or job execution, typically for background tasks or jobs.
|
|
@@ -233,6 +234,10 @@ export type LogEvent = {
|
|
|
233
234
|
* Represents an error or exception.
|
|
234
235
|
*/
|
|
235
236
|
error?: LogError;
|
|
237
|
+
/**
|
|
238
|
+
* The duration, in milliseconds, that it took to complete this event.
|
|
239
|
+
*/
|
|
240
|
+
duration?: TimeMs;
|
|
236
241
|
/**
|
|
237
242
|
* Represents a HTTP request, both incoming and outgoing. Note the direction field.
|
|
238
243
|
*/
|
|
@@ -250,6 +255,10 @@ export type LogEvent = {
|
|
|
250
255
|
request_id?: HttpRequestId;
|
|
251
256
|
scheme?: HttpScheme;
|
|
252
257
|
service_name?: HttpServiceName;
|
|
258
|
+
start_time?: TimeMs;
|
|
259
|
+
path_parameters?: Record<string, string | undefined>;
|
|
260
|
+
query_parameters?: Record<string, string | string[] | undefined>;
|
|
261
|
+
route_key?: string;
|
|
253
262
|
};
|
|
254
263
|
/**
|
|
255
264
|
* Represents a HTTP response event, both outgoing and incoming. Note the direction field.
|
|
@@ -263,17 +272,7 @@ export type LogEvent = {
|
|
|
263
272
|
request_id?: HttpRequestId;
|
|
264
273
|
service_name?: HttpServiceName;
|
|
265
274
|
status: HttpStatus;
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* The request being responded to. This couples the request data with the response event avoiding the need for joins or external data dependencies. In many cases the data must be coupled with this event because it is represented as a single event (nginx, apache web server, and other reverse proxy servers).
|
|
269
|
-
*/
|
|
270
|
-
request?: {
|
|
271
|
-
[k: string]: any;
|
|
272
|
-
host?: HttpHost;
|
|
273
|
-
method?: HttpMethod;
|
|
274
|
-
path?: HttpPath;
|
|
275
|
-
scheme?: HttpScheme;
|
|
276
|
-
};
|
|
275
|
+
end_time?: TimeMs;
|
|
277
276
|
};
|
|
278
277
|
};
|
|
279
278
|
export type LogEntry = {
|
|
@@ -293,10 +292,6 @@ export type LogEntry = {
|
|
|
293
292
|
* A controlled representation of the event this log line represents.
|
|
294
293
|
*/
|
|
295
294
|
event?: LogEvent | undefined;
|
|
296
|
-
/**
|
|
297
|
-
* Only print the message line, not the metadata.
|
|
298
|
-
*/
|
|
299
|
-
messageOnly?: boolean;
|
|
300
295
|
};
|
|
301
296
|
export type LogMetadata = {
|
|
302
297
|
error?: Error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/logger",
|
|
3
|
-
"version": "11.121.
|
|
3
|
+
"version": "11.121.9",
|
|
4
4
|
"description": "Logging utility.",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lodash": "4.17.21"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@sentry/
|
|
28
|
+
"@sentry/core": "8.55.0",
|
|
29
29
|
"@types/lodash": "4.17.20",
|
|
30
30
|
"graphql": "16.10.0"
|
|
31
31
|
},
|