sdk-logs 0.6.13 → 0.8.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/domain.objects/LogOutlet.d.ts +33 -0
- package/dist/domain.objects/LogOutlet.js +3 -0
- package/dist/domain.objects/LogOutlet.js.map +1 -0
- package/dist/domain.objects/LogTrail.d.ts +20 -4
- package/dist/domain.operations/asCurrentIsoTimestamp.d.ts +5 -0
- package/dist/domain.operations/asCurrentIsoTimestamp.js +12 -0
- package/dist/domain.operations/asCurrentIsoTimestamp.js.map +1 -0
- package/dist/domain.operations/formatLogContentsForEnvironment.d.ts +20 -1
- package/dist/domain.operations/formatLogContentsForEnvironment.js +22 -6
- package/dist/domain.operations/formatLogContentsForEnvironment.js.map +1 -1
- package/dist/domain.operations/genContextLogTrail.d.ts +28 -0
- package/dist/domain.operations/genContextLogTrail.js +58 -0
- package/dist/domain.operations/genContextLogTrail.js.map +1 -0
- package/dist/domain.operations/{generateLogMethods.d.ts → genLogMethods.d.ts} +13 -2
- package/dist/domain.operations/genLogMethods.js +42 -0
- package/dist/domain.operations/genLogMethods.js.map +1 -0
- package/dist/domain.operations/generateLogMethod.d.ts +8 -1
- package/dist/domain.operations/generateLogMethod.js +32 -14
- package/dist/domain.operations/generateLogMethod.js.map +1 -1
- package/dist/domain.operations/outlets/cloudwatch/asCloudWatchBatches.d.ts +8 -0
- package/dist/domain.operations/outlets/cloudwatch/asCloudWatchBatches.js +47 -0
- package/dist/domain.operations/outlets/cloudwatch/asCloudWatchBatches.js.map +1 -0
- package/dist/domain.operations/outlets/cloudwatch/asCloudWatchLogEvents.d.ts +9 -0
- package/dist/domain.operations/outlets/cloudwatch/asCloudWatchLogEvents.js +15 -0
- package/dist/domain.operations/outlets/cloudwatch/asCloudWatchLogEvents.js.map +1 -0
- package/dist/domain.operations/outlets/cloudwatch/asDefaultLogStreamName.d.ts +6 -0
- package/dist/domain.operations/outlets/cloudwatch/asDefaultLogStreamName.js +24 -0
- package/dist/domain.operations/outlets/cloudwatch/asDefaultLogStreamName.js.map +1 -0
- package/dist/domain.operations/outlets/cloudwatch/asLambdaStyleLogGroupName.d.ts +18 -0
- package/dist/domain.operations/outlets/cloudwatch/asLambdaStyleLogGroupName.js +57 -0
- package/dist/domain.operations/outlets/cloudwatch/asLambdaStyleLogGroupName.js.map +1 -0
- package/dist/domain.operations/outlets/cloudwatch/assertAwsCredentialsPresent.d.ts +8 -0
- package/dist/domain.operations/outlets/cloudwatch/assertAwsCredentialsPresent.js +46 -0
- package/dist/domain.operations/outlets/cloudwatch/assertAwsCredentialsPresent.js.map +1 -0
- package/dist/domain.operations/outlets/cloudwatch/computeLogEventSize.d.ts +8 -0
- package/dist/domain.operations/outlets/cloudwatch/computeLogEventSize.js +15 -0
- package/dist/domain.operations/outlets/cloudwatch/computeLogEventSize.js.map +1 -0
- package/dist/domain.operations/outlets/cloudwatch/drainBuffer.d.ts +6 -0
- package/dist/domain.operations/outlets/cloudwatch/drainBuffer.js +12 -0
- package/dist/domain.operations/outlets/cloudwatch/drainBuffer.js.map +1 -0
- package/dist/domain.operations/outlets/cloudwatch/genCloudwatchOutlet.d.ts +24 -0
- package/dist/domain.operations/outlets/cloudwatch/genCloudwatchOutlet.js +205 -0
- package/dist/domain.operations/outlets/cloudwatch/genCloudwatchOutlet.js.map +1 -0
- package/dist/domain.operations/withLogTrail.d.ts +1 -1
- package/dist/domain.operations/withLogTrail.js +58 -26
- package/dist/domain.operations/withLogTrail.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/dist/domain.operations/generateLogMethods.js +0 -22
- package/dist/domain.operations/generateLogMethods.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LogLevel } from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* .what = a log event that flows through outlets
|
|
4
|
+
* .why = standardized shape for log data across destinations
|
|
5
|
+
*/
|
|
6
|
+
export interface LogEvent {
|
|
7
|
+
level: LogLevel;
|
|
8
|
+
timestamp: string;
|
|
9
|
+
message: string;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* .what = an outlet that receives log events
|
|
14
|
+
* .why = enables logs to route to external destinations (e.g., CloudWatch)
|
|
15
|
+
*/
|
|
16
|
+
export interface LogOutlet {
|
|
17
|
+
/**
|
|
18
|
+
* .what = send a log event to this outlet
|
|
19
|
+
* .why = buffers or dispatches the event to the destination
|
|
20
|
+
*/
|
|
21
|
+
send: (event: LogEvent) => void;
|
|
22
|
+
/**
|
|
23
|
+
* .what = flush buffered events to the destination
|
|
24
|
+
* .why = ensures all buffered logs are sent before process exit
|
|
25
|
+
*/
|
|
26
|
+
flush: () => Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* .what = close the outlet and release resources
|
|
29
|
+
* .why = cleans up timers and process listeners to prevent leaks in tests
|
|
30
|
+
* .note = optional - not all outlets require cleanup
|
|
31
|
+
*/
|
|
32
|
+
close?: () => void;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogOutlet.js","sourceRoot":"","sources":["../../src/domain.objects/LogOutlet.ts"],"names":[],"mappings":""}
|
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
import type { Procedure, ProcedureContext } from 'domain-glossary-procedure';
|
|
2
|
-
import type { LogMethods } from '../domain.operations/
|
|
2
|
+
import type { LogMethods } from '../domain.operations/genLogMethods';
|
|
3
3
|
/**
|
|
4
|
-
* .what = the procedure invocation trail
|
|
4
|
+
* .what = the procedure invocation trail with external identifier
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export interface LogTrail {
|
|
7
|
+
/**
|
|
8
|
+
* .what = external identifier for request correlation
|
|
9
|
+
* .why = enables log correlation across a single request
|
|
10
|
+
*/
|
|
11
|
+
exid: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* .what = the procedure call stack
|
|
14
|
+
* .why = tracks call depth through withLogTrail wraps
|
|
15
|
+
*/
|
|
16
|
+
stack: string[];
|
|
17
|
+
}
|
|
7
18
|
export interface ContextLogTrail {
|
|
8
19
|
/**
|
|
9
20
|
* .what = the log context which can be used; methods, trail, etc
|
|
10
21
|
*/
|
|
11
22
|
log: LogMethods & {
|
|
12
23
|
_orig?: LogMethods;
|
|
13
|
-
} & {
|
|
14
24
|
/**
|
|
15
25
|
* .what = the log trail which has been collected
|
|
16
26
|
*/
|
|
17
27
|
trail?: LogTrail;
|
|
28
|
+
/**
|
|
29
|
+
* .what = environment context for log output
|
|
30
|
+
*/
|
|
31
|
+
env?: {
|
|
32
|
+
commit: string;
|
|
33
|
+
};
|
|
18
34
|
};
|
|
19
35
|
}
|
|
20
36
|
export type HasContextLogTrail<T extends Procedure> = ProcedureContext<T> extends ContextLogTrail ? T : never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asCurrentIsoTimestamp = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = returns current UTC timestamp in ISO 8601 format
|
|
6
|
+
* .why = extracts decode-friction from orchestrators
|
|
7
|
+
*/
|
|
8
|
+
const asCurrentIsoTimestamp = () => {
|
|
9
|
+
return new Date().toISOString();
|
|
10
|
+
};
|
|
11
|
+
exports.asCurrentIsoTimestamp = asCurrentIsoTimestamp;
|
|
12
|
+
//# sourceMappingURL=asCurrentIsoTimestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asCurrentIsoTimestamp.js","sourceRoot":"","sources":["../../src/domain.operations/asCurrentIsoTimestamp.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,qBAAqB,GAAG,GAAW,EAAE;IAChD,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,qBAAqB,yBAEhC"}
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
import { type LogLevel } from '../domain.objects/constants';
|
|
2
|
-
|
|
2
|
+
import type { LogTrail } from '../domain.objects/LogTrail';
|
|
3
|
+
export declare const formatLogContentsForEnvironment: ({ level, timestamp, message, metadata, trail, env, }: {
|
|
3
4
|
level: LogLevel;
|
|
4
5
|
timestamp: string;
|
|
5
6
|
message: string;
|
|
6
7
|
metadata?: Record<string, any>;
|
|
8
|
+
trail?: LogTrail;
|
|
9
|
+
env?: {
|
|
10
|
+
commit: string;
|
|
11
|
+
};
|
|
7
12
|
}) => string | {
|
|
13
|
+
env?: {
|
|
14
|
+
commit: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
trail?: {
|
|
17
|
+
stack: string[];
|
|
18
|
+
exid?: string | undefined;
|
|
19
|
+
} | undefined;
|
|
8
20
|
level: LogLevel;
|
|
9
21
|
timestamp: string;
|
|
10
22
|
message: string;
|
|
11
23
|
metadata: string;
|
|
12
24
|
} | {
|
|
25
|
+
env?: {
|
|
26
|
+
commit: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
trail?: {
|
|
29
|
+
stack: string[];
|
|
30
|
+
exid?: string | undefined;
|
|
31
|
+
} | undefined;
|
|
13
32
|
level: LogLevel;
|
|
14
33
|
timestamp: string;
|
|
15
34
|
message: string;
|
|
@@ -1,39 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatLogContentsForEnvironment = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
4
5
|
const constants_1 = require("../domain.objects/constants");
|
|
5
6
|
const identifyEnvironment_1 = require("./identifyEnvironment");
|
|
6
|
-
const formatLogContentsForEnvironment = ({ level, timestamp, message, metadata, }) => {
|
|
7
|
-
const
|
|
7
|
+
const formatLogContentsForEnvironment = ({ level, timestamp, message, metadata, trail, env, }) => {
|
|
8
|
+
const environment = (0, identifyEnvironment_1.identifyEnvironment)();
|
|
9
|
+
// build trail output: omit if not provided, omit exid if null
|
|
10
|
+
const trailOutput = trail
|
|
11
|
+
? {
|
|
12
|
+
...(trail.exid !== null ? { exid: trail.exid } : {}),
|
|
13
|
+
stack: trail.stack,
|
|
14
|
+
}
|
|
15
|
+
: undefined;
|
|
16
|
+
// build env output: omit if not provided or commit is null
|
|
17
|
+
const envOutput = env?.commit ? { commit: env.commit } : undefined;
|
|
8
18
|
// if its a "local" environment, then dont stringify the contents - but stringify the metadata to cut down on visual noise
|
|
9
|
-
if (
|
|
19
|
+
if (environment === constants_1.SupportedEnvironment.LOCAL) {
|
|
10
20
|
return {
|
|
11
21
|
level,
|
|
12
22
|
timestamp,
|
|
13
23
|
message,
|
|
14
24
|
metadata: JSON.stringify(metadata), // json stringify it to cut down on the visual noise in the console
|
|
25
|
+
...(trailOutput ? { trail: trailOutput } : {}),
|
|
26
|
+
...(envOutput ? { env: envOutput } : {}),
|
|
15
27
|
};
|
|
16
28
|
}
|
|
17
29
|
// if its an aws-lambda environment, then stringify the contents - without stringifying the metadata - to make sure log is fully readable and parseable by cloudwatch
|
|
18
|
-
if (
|
|
30
|
+
if (environment === constants_1.SupportedEnvironment.AWS_LAMBDA) {
|
|
19
31
|
return JSON.stringify({
|
|
20
32
|
level,
|
|
21
33
|
timestamp,
|
|
22
34
|
message,
|
|
23
35
|
metadata,
|
|
36
|
+
...(trailOutput ? { trail: trailOutput } : {}),
|
|
37
|
+
...(envOutput ? { env: envOutput } : {}),
|
|
24
38
|
});
|
|
25
39
|
}
|
|
26
40
|
// if its a web-browser environment, then dont stringify the contents - nor the metadata - to make sure log is fully accessible through console devtools
|
|
27
|
-
if (
|
|
41
|
+
if (environment === constants_1.SupportedEnvironment.WEB_BROWSER) {
|
|
28
42
|
return {
|
|
29
43
|
level,
|
|
30
44
|
timestamp,
|
|
31
45
|
message,
|
|
32
46
|
metadata,
|
|
47
|
+
...(trailOutput ? { trail: trailOutput } : {}),
|
|
48
|
+
...(envOutput ? { env: envOutput } : {}),
|
|
33
49
|
};
|
|
34
50
|
}
|
|
35
51
|
// if it was not one of the above, we have not supported this environment yet
|
|
36
|
-
throw new
|
|
52
|
+
throw new helpful_errors_1.UnexpectedCodePathError('unsupported environment detected. this should never occur - and is a bug within sdk-logs');
|
|
37
53
|
};
|
|
38
54
|
exports.formatLogContentsForEnvironment = formatLogContentsForEnvironment;
|
|
39
55
|
//# sourceMappingURL=formatLogContentsForEnvironment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatLogContentsForEnvironment.js","sourceRoot":"","sources":["../../src/domain.operations/formatLogContentsForEnvironment.ts"],"names":[],"mappings":";;;AAAA,6DAGuC;
|
|
1
|
+
{"version":3,"file":"formatLogContentsForEnvironment.js","sourceRoot":"","sources":["../../src/domain.operations/formatLogContentsForEnvironment.ts"],"names":[],"mappings":";;;AAAA,mDAAyD;AAEzD,6DAGuC;AAGvC,+DAA4D;AAErD,MAAM,+BAA+B,GAAG,CAAC,EAC9C,KAAK,EACL,SAAS,EACT,OAAO,EACP,QAAQ,EACR,KAAK,EACL,GAAG,GAQJ,EAAE,EAAE;IACH,MAAM,WAAW,GAAG,IAAA,yCAAmB,GAAE,CAAC;IAE1C,8DAA8D;IAC9D,MAAM,WAAW,GAAG,KAAK;QACvB,CAAC,CAAC;YACE,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpD,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,2DAA2D;IAC3D,MAAM,SAAS,GAAG,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnE,0HAA0H;IAC1H,IAAI,WAAW,KAAK,gCAAoB,CAAC,KAAK,EAAE,CAAC;QAC/C,OAAO;YACL,KAAK;YACL,SAAS;YACT,OAAO;YACP,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mEAAmE;YACvG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9C,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzC,CAAC;IACJ,CAAC;IAED,qKAAqK;IACrK,IAAI,WAAW,KAAK,gCAAoB,CAAC,UAAU,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,KAAK;YACL,SAAS;YACT,OAAO;YACP,QAAQ;YACR,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9C,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzC,CAAC,CAAC;IACL,CAAC;IAED,wJAAwJ;IACxJ,IAAI,WAAW,KAAK,gCAAoB,CAAC,WAAW,EAAE,CAAC;QACrD,OAAO;YACL,KAAK;YACL,SAAS;YACT,OAAO;YACP,QAAQ;YACR,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9C,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzC,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,MAAM,IAAI,wCAAuB,CAC/B,0FAA0F,CAC3F,CAAC;AACJ,CAAC,CAAC;AApEW,QAAA,+BAA+B,mCAoE1C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LogLevel } from '../domain.objects/constants';
|
|
2
|
+
import type { ContextLogTrail } from '../domain.objects/LogTrail';
|
|
3
|
+
/**
|
|
4
|
+
* .what = create a log context with trail and env injection
|
|
5
|
+
* .why = enables request correlation via trail.exid and code version via env.commit
|
|
6
|
+
*/
|
|
7
|
+
export declare const genContextLogTrail: ({ trail, env, minimalLogLevel, }: {
|
|
8
|
+
/**
|
|
9
|
+
* .what = the trail context for log correlation
|
|
10
|
+
* .why = forces caller to explicitly provide or pass null
|
|
11
|
+
*/
|
|
12
|
+
trail: {
|
|
13
|
+
exid: string | null;
|
|
14
|
+
stack: string[];
|
|
15
|
+
} | null;
|
|
16
|
+
/**
|
|
17
|
+
* .what = the environment context
|
|
18
|
+
* .why = forces caller to explicitly provide or pass null
|
|
19
|
+
*/
|
|
20
|
+
env: {
|
|
21
|
+
commit: string | null;
|
|
22
|
+
} | null;
|
|
23
|
+
/**
|
|
24
|
+
* .what = the minimum log level to emit
|
|
25
|
+
* .why = allows filter of logs by level
|
|
26
|
+
*/
|
|
27
|
+
minimalLogLevel?: LogLevel;
|
|
28
|
+
}) => ContextLogTrail;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genContextLogTrail = void 0;
|
|
4
|
+
const constants_1 = require("../domain.objects/constants");
|
|
5
|
+
const generateLogMethod_1 = require("./generateLogMethod");
|
|
6
|
+
const getRecommendedMinimalLogLevelForEnvironment_1 = require("./getRecommendedMinimalLogLevelForEnvironment");
|
|
7
|
+
/**
|
|
8
|
+
* .what = create a log context with trail and env injection
|
|
9
|
+
* .why = enables request correlation via trail.exid and code version via env.commit
|
|
10
|
+
*/
|
|
11
|
+
const genContextLogTrail = ({ trail, env, minimalLogLevel = (0, getRecommendedMinimalLogLevelForEnvironment_1.getRecommendedMinimalLogLevelForEnvironment)(), }) => {
|
|
12
|
+
// build the trail object: only include if provided
|
|
13
|
+
const trailForLog = trail
|
|
14
|
+
? { exid: trail.exid, stack: trail.stack }
|
|
15
|
+
: undefined;
|
|
16
|
+
// build the env object: only include if commit is not null
|
|
17
|
+
const envForLog = env?.commit !== null && env?.commit !== undefined
|
|
18
|
+
? { commit: env.commit }
|
|
19
|
+
: undefined;
|
|
20
|
+
// generate the log methods with trail/env injected
|
|
21
|
+
const logMethods = {
|
|
22
|
+
error: (0, generateLogMethod_1.generateLogMethod)({
|
|
23
|
+
level: constants_1.LogLevel.ERROR,
|
|
24
|
+
minimalLogLevel,
|
|
25
|
+
trail: trailForLog,
|
|
26
|
+
env: envForLog,
|
|
27
|
+
}),
|
|
28
|
+
warn: (0, generateLogMethod_1.generateLogMethod)({
|
|
29
|
+
level: constants_1.LogLevel.WARN,
|
|
30
|
+
minimalLogLevel,
|
|
31
|
+
trail: trailForLog,
|
|
32
|
+
env: envForLog,
|
|
33
|
+
}),
|
|
34
|
+
info: (0, generateLogMethod_1.generateLogMethod)({
|
|
35
|
+
level: constants_1.LogLevel.INFO,
|
|
36
|
+
minimalLogLevel,
|
|
37
|
+
trail: trailForLog,
|
|
38
|
+
env: envForLog,
|
|
39
|
+
}),
|
|
40
|
+
debug: (0, generateLogMethod_1.generateLogMethod)({
|
|
41
|
+
level: constants_1.LogLevel.DEBUG,
|
|
42
|
+
minimalLogLevel,
|
|
43
|
+
trail: trailForLog,
|
|
44
|
+
env: envForLog,
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
// return the context with log methods, trail, env, and config
|
|
48
|
+
return {
|
|
49
|
+
log: {
|
|
50
|
+
...logMethods,
|
|
51
|
+
trail: trailForLog,
|
|
52
|
+
env: envForLog,
|
|
53
|
+
_: Object.freeze({ level: minimalLogLevel }),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.genContextLogTrail = genContextLogTrail;
|
|
58
|
+
//# sourceMappingURL=genContextLogTrail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genContextLogTrail.js","sourceRoot":"","sources":["../../src/domain.operations/genContextLogTrail.ts"],"names":[],"mappings":";;;AAAA,6DAAyD;AAGzD,2DAAwD;AACxD,+GAA4G;AAE5G;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAAC,EACjC,KAAK,EACL,GAAG,EACH,eAAe,GAAG,IAAA,yFAA2C,GAAE,GAwBhE,EAAmB,EAAE;IACpB,mDAAmD;IACnD,MAAM,WAAW,GAAyB,KAAK;QAC7C,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;QAC1C,CAAC,CAAC,SAAS,CAAC;IAEd,2DAA2D;IAC3D,MAAM,SAAS,GACb,GAAG,EAAE,MAAM,KAAK,IAAI,IAAI,GAAG,EAAE,MAAM,KAAK,SAAS;QAC/C,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE;QACxB,CAAC,CAAC,SAAS,CAAC;IAEhB,mDAAmD;IACnD,MAAM,UAAU,GAAG;QACjB,KAAK,EAAE,IAAA,qCAAiB,EAAC;YACvB,KAAK,EAAE,oBAAQ,CAAC,KAAK;YACrB,eAAe;YACf,KAAK,EAAE,WAAW;YAClB,GAAG,EAAE,SAAS;SACf,CAAC;QACF,IAAI,EAAE,IAAA,qCAAiB,EAAC;YACtB,KAAK,EAAE,oBAAQ,CAAC,IAAI;YACpB,eAAe;YACf,KAAK,EAAE,WAAW;YAClB,GAAG,EAAE,SAAS;SACf,CAAC;QACF,IAAI,EAAE,IAAA,qCAAiB,EAAC;YACtB,KAAK,EAAE,oBAAQ,CAAC,IAAI;YACpB,eAAe;YACf,KAAK,EAAE,WAAW;YAClB,GAAG,EAAE,SAAS;SACf,CAAC;QACF,KAAK,EAAE,IAAA,qCAAiB,EAAC;YACvB,KAAK,EAAE,oBAAQ,CAAC,KAAK;YACrB,eAAe;YACf,KAAK,EAAE,WAAW;YAClB,GAAG,EAAE,SAAS;SACf,CAAC;KACH,CAAC;IAEF,8DAA8D;IAC9D,OAAO;QACL,GAAG,EAAE;YACH,GAAG,UAAU;YACb,KAAK,EAAE,WAAW;YAClB,GAAG,EAAE,SAAS;YACd,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;SAC7C;KACF,CAAC;AACJ,CAAC,CAAC;AA5EW,QAAA,kBAAkB,sBA4E7B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LogLevel } from '../domain.objects/constants';
|
|
2
|
+
import type { LogOutlet } from '../domain.objects/LogOutlet';
|
|
2
3
|
import { type LogMethod } from './generateLogMethod';
|
|
3
4
|
export interface LogMethods {
|
|
4
5
|
/**
|
|
@@ -25,12 +26,22 @@ export interface LogMethods {
|
|
|
25
26
|
* - when choosing to log something with a log level of "debug", you are saying that someone will only be interested in this information when debugging
|
|
26
27
|
*/
|
|
27
28
|
debug: LogMethod;
|
|
29
|
+
/**
|
|
30
|
+
* .what = internal config for log methods
|
|
31
|
+
*/
|
|
32
|
+
readonly _: Readonly<{
|
|
33
|
+
level: LogLevel;
|
|
34
|
+
}>;
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
37
|
* define how to generate the log methods
|
|
31
38
|
* - allows you to specify the minimal log level to use for your application
|
|
32
39
|
* - defaults to recommended levels for the environment
|
|
40
|
+
* - allows you to specify outlets for log events to flow to external destinations
|
|
33
41
|
*/
|
|
34
|
-
export declare const
|
|
35
|
-
|
|
42
|
+
export declare const genLogMethods: ({ level, outlets, }?: {
|
|
43
|
+
level?: {
|
|
44
|
+
minimum?: LogLevel;
|
|
45
|
+
};
|
|
46
|
+
outlets?: LogOutlet[];
|
|
36
47
|
}) => LogMethods;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genLogMethods = void 0;
|
|
4
|
+
const constants_1 = require("../domain.objects/constants");
|
|
5
|
+
const generateLogMethod_1 = require("./generateLogMethod");
|
|
6
|
+
const getRecommendedMinimalLogLevelForEnvironment_1 = require("./getRecommendedMinimalLogLevelForEnvironment");
|
|
7
|
+
/**
|
|
8
|
+
* define how to generate the log methods
|
|
9
|
+
* - allows you to specify the minimal log level to use for your application
|
|
10
|
+
* - defaults to recommended levels for the environment
|
|
11
|
+
* - allows you to specify outlets for log events to flow to external destinations
|
|
12
|
+
*/
|
|
13
|
+
const genLogMethods = ({ level, outlets, } = {}) => {
|
|
14
|
+
// derive minimal log level
|
|
15
|
+
const derivedMinimalLogLevel = level?.minimum ?? (0, getRecommendedMinimalLogLevelForEnvironment_1.getRecommendedMinimalLogLevelForEnvironment)();
|
|
16
|
+
// generate the methods
|
|
17
|
+
return {
|
|
18
|
+
error: (0, generateLogMethod_1.generateLogMethod)({
|
|
19
|
+
level: constants_1.LogLevel.ERROR,
|
|
20
|
+
minimalLogLevel: derivedMinimalLogLevel,
|
|
21
|
+
outlets,
|
|
22
|
+
}),
|
|
23
|
+
warn: (0, generateLogMethod_1.generateLogMethod)({
|
|
24
|
+
level: constants_1.LogLevel.WARN,
|
|
25
|
+
minimalLogLevel: derivedMinimalLogLevel,
|
|
26
|
+
outlets,
|
|
27
|
+
}),
|
|
28
|
+
info: (0, generateLogMethod_1.generateLogMethod)({
|
|
29
|
+
level: constants_1.LogLevel.INFO,
|
|
30
|
+
minimalLogLevel: derivedMinimalLogLevel,
|
|
31
|
+
outlets,
|
|
32
|
+
}),
|
|
33
|
+
debug: (0, generateLogMethod_1.generateLogMethod)({
|
|
34
|
+
level: constants_1.LogLevel.DEBUG,
|
|
35
|
+
minimalLogLevel: derivedMinimalLogLevel,
|
|
36
|
+
outlets,
|
|
37
|
+
}),
|
|
38
|
+
_: Object.freeze({ level: derivedMinimalLogLevel }),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.genLogMethods = genLogMethods;
|
|
42
|
+
//# sourceMappingURL=genLogMethods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genLogMethods.js","sourceRoot":"","sources":["../../src/domain.operations/genLogMethods.ts"],"names":[],"mappings":";;;AAAA,6DAAyD;AAGzD,2DAAwE;AACxE,+GAA4G;AAqC5G;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,EAC5B,KAAK,EACL,OAAO,MAIL,EAAE,EAAc,EAAE;IACpB,2BAA2B;IAC3B,MAAM,sBAAsB,GAC1B,KAAK,EAAE,OAAO,IAAI,IAAA,yFAA2C,GAAE,CAAC;IAElE,uBAAuB;IACvB,OAAO;QACL,KAAK,EAAE,IAAA,qCAAiB,EAAC;YACvB,KAAK,EAAE,oBAAQ,CAAC,KAAK;YACrB,eAAe,EAAE,sBAAsB;YACvC,OAAO;SACR,CAAC;QACF,IAAI,EAAE,IAAA,qCAAiB,EAAC;YACtB,KAAK,EAAE,oBAAQ,CAAC,IAAI;YACpB,eAAe,EAAE,sBAAsB;YACvC,OAAO;SACR,CAAC;QACF,IAAI,EAAE,IAAA,qCAAiB,EAAC;YACtB,KAAK,EAAE,oBAAQ,CAAC,IAAI;YACpB,eAAe,EAAE,sBAAsB;YACvC,OAAO;SACR,CAAC;QACF,KAAK,EAAE,IAAA,qCAAiB,EAAC;YACvB,KAAK,EAAE,oBAAQ,CAAC,KAAK;YACrB,eAAe,EAAE,sBAAsB;YACvC,OAAO;SACR,CAAC;QACF,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC;KACpD,CAAC;AACJ,CAAC,CAAC;AAnCW,QAAA,aAAa,iBAmCxB"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { LogLevel } from '../domain.objects/constants';
|
|
2
|
+
import type { LogOutlet } from '../domain.objects/LogOutlet';
|
|
3
|
+
import type { LogTrail } from '../domain.objects/LogTrail';
|
|
2
4
|
export type LogMethod = (message: string, metadata?: any) => void;
|
|
3
|
-
export declare const generateLogMethod: ({ level, minimalLogLevel, }: {
|
|
5
|
+
export declare const generateLogMethod: ({ level, minimalLogLevel, trail, env, outlets, }: {
|
|
4
6
|
level: LogLevel;
|
|
5
7
|
minimalLogLevel: LogLevel;
|
|
8
|
+
trail?: LogTrail;
|
|
9
|
+
env?: {
|
|
10
|
+
commit: string;
|
|
11
|
+
};
|
|
12
|
+
outlets?: LogOutlet[];
|
|
6
13
|
}) => (message: string, metadata?: object) => void;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateLogMethod = void 0;
|
|
4
4
|
const constants_1 = require("../domain.objects/constants");
|
|
5
|
+
const asCurrentIsoTimestamp_1 = require("./asCurrentIsoTimestamp");
|
|
5
6
|
const formatLogContentsForEnvironment_1 = require("./formatLogContentsForEnvironment");
|
|
6
7
|
/*
|
|
7
8
|
define priority order of log levels and make it easy to ask questions about
|
|
@@ -13,23 +14,40 @@ const logLevelPriorityOrder = [
|
|
|
13
14
|
constants_1.LogLevel.DEBUG,
|
|
14
15
|
];
|
|
15
16
|
const aIsEqualOrMoreImportantThanB = ({ a, b }) => logLevelPriorityOrder.indexOf(a) - logLevelPriorityOrder.indexOf(b) <= 0;
|
|
16
|
-
const generateLogMethod = ({ level, minimalLogLevel, }) => {
|
|
17
|
+
const generateLogMethod = ({ level, minimalLogLevel, trail, env, outlets, }) => {
|
|
17
18
|
return (message, metadata) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
// check level threshold
|
|
20
|
+
if (!aIsEqualOrMoreImportantThanB({ a: level, b: minimalLogLevel }))
|
|
21
|
+
return;
|
|
22
|
+
// create timestamp once for consistency
|
|
23
|
+
const timestamp = (0, asCurrentIsoTimestamp_1.asCurrentIsoTimestamp)();
|
|
24
|
+
// determine the console level (i.e., use warn if we can to make the logs stand out more)
|
|
25
|
+
const consoleMethod = aIsEqualOrMoreImportantThanB({
|
|
26
|
+
a: level,
|
|
27
|
+
b: constants_1.LogLevel.WARN,
|
|
28
|
+
})
|
|
29
|
+
? console.warn
|
|
30
|
+
: console.log; // tslint:disable-line no-console
|
|
31
|
+
// output the message to console, which will get picked up by cloudwatch when deployed lambda is invoked
|
|
32
|
+
consoleMethod((0, formatLogContentsForEnvironment_1.formatLogContentsForEnvironment)({
|
|
33
|
+
level,
|
|
34
|
+
timestamp,
|
|
35
|
+
message,
|
|
36
|
+
metadata,
|
|
37
|
+
trail,
|
|
38
|
+
env,
|
|
39
|
+
}));
|
|
40
|
+
// dispatch to outlets (fail-fast: errors propagate to caller)
|
|
41
|
+
if (outlets && outlets.length > 0) {
|
|
42
|
+
const event = {
|
|
28
43
|
level,
|
|
29
|
-
timestamp
|
|
44
|
+
timestamp,
|
|
30
45
|
message,
|
|
31
|
-
metadata,
|
|
32
|
-
}
|
|
46
|
+
metadata: metadata,
|
|
47
|
+
};
|
|
48
|
+
for (const outlet of outlets) {
|
|
49
|
+
outlet.send(event);
|
|
50
|
+
}
|
|
33
51
|
}
|
|
34
52
|
};
|
|
35
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateLogMethod.js","sourceRoot":"","sources":["../../src/domain.operations/generateLogMethod.ts"],"names":[],"mappings":";;;AAAA,6DAAyD;
|
|
1
|
+
{"version":3,"file":"generateLogMethod.js","sourceRoot":"","sources":["../../src/domain.operations/generateLogMethod.ts"],"names":[],"mappings":";;;AAAA,6DAAyD;AAIzD,mEAAgE;AAChE,uFAAoF;AAEpF;;EAEE;AACF,MAAM,qBAAqB,GAAG;IAC5B,oBAAQ,CAAC,KAAK;IACd,oBAAQ,CAAC,IAAI;IACb,oBAAQ,CAAC,IAAI;IACb,oBAAQ,CAAC,KAAK;CACf,CAAC;AACF,MAAM,4BAA4B,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAgC,EAAE,EAAE,CAC9E,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAUpE,MAAM,iBAAiB,GAAG,CAAC,EAChC,KAAK,EACL,eAAe,EACf,KAAK,EACL,GAAG,EACH,OAAO,GAOR,EAAE,EAAE;IACH,OAAO,CAAC,OAAe,EAAE,QAAiB,EAAE,EAAE;QAC5C,wBAAwB;QACxB,IAAI,CAAC,4BAA4B,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC;YAAE,OAAO;QAE5E,wCAAwC;QACxC,MAAM,SAAS,GAAG,IAAA,6CAAqB,GAAE,CAAC;QAE1C,yFAAyF;QACzF,MAAM,aAAa,GAAG,4BAA4B,CAAC;YACjD,CAAC,EAAE,KAAK;YACR,CAAC,EAAE,oBAAQ,CAAC,IAAI;SACjB,CAAC;YACA,CAAC,CAAC,OAAO,CAAC,IAAI;YACd,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,iCAAiC;QAElD,wGAAwG;QACxG,aAAa,CACX,IAAA,iEAA+B,EAAC;YAC9B,KAAK;YACL,SAAS;YACT,OAAO;YACP,QAAQ;YACR,KAAK;YACL,GAAG;SACJ,CAAC,CACH,CAAC;QAEF,8DAA8D;QAC9D,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClC,MAAM,KAAK,GAAa;gBACtB,KAAK;gBACL,SAAS;gBACT,OAAO;gBACP,QAAQ,EAAE,QAA+C;aAC1D,CAAC;YACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AArDW,QAAA,iBAAiB,qBAqD5B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LogEvent } from '../../../domain.objects/LogOutlet';
|
|
2
|
+
/**
|
|
3
|
+
* .what = splits log events into CloudWatch-compliant batches
|
|
4
|
+
* .why = CloudWatch rejects batches over 1MB or 10k events
|
|
5
|
+
*
|
|
6
|
+
* @returns array of batches, each within CloudWatch limits
|
|
7
|
+
*/
|
|
8
|
+
export declare const asCloudWatchBatches: (events: LogEvent[]) => LogEvent[][];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asCloudWatchBatches = void 0;
|
|
4
|
+
const computeLogEventSize_1 = require("./computeLogEventSize");
|
|
5
|
+
/**
|
|
6
|
+
* .what = CloudWatch PutLogEvents limits
|
|
7
|
+
* .why = CloudWatch rejects batches that exceed these limits
|
|
8
|
+
*
|
|
9
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
|
|
10
|
+
*/
|
|
11
|
+
const CLOUDWATCH_MAX_BATCH_SIZE = 1048576; // 1MB
|
|
12
|
+
const CLOUDWATCH_MAX_BATCH_COUNT = 10000;
|
|
13
|
+
const CLOUDWATCH_EVENT_OVERHEAD = 26; // bytes per event
|
|
14
|
+
/**
|
|
15
|
+
* .what = splits log events into CloudWatch-compliant batches
|
|
16
|
+
* .why = CloudWatch rejects batches over 1MB or 10k events
|
|
17
|
+
*
|
|
18
|
+
* @returns array of batches, each within CloudWatch limits
|
|
19
|
+
*/
|
|
20
|
+
const asCloudWatchBatches = (events) => {
|
|
21
|
+
if (events.length === 0)
|
|
22
|
+
return [];
|
|
23
|
+
const batches = [];
|
|
24
|
+
let currentBatch = [];
|
|
25
|
+
let currentBatchSize = 0;
|
|
26
|
+
for (const event of events) {
|
|
27
|
+
const eventSize = (0, computeLogEventSize_1.computeLogEventSize)(event) + CLOUDWATCH_EVENT_OVERHEAD;
|
|
28
|
+
// check if event would exceed batch limits
|
|
29
|
+
const wouldExceedSize = currentBatchSize + eventSize > CLOUDWATCH_MAX_BATCH_SIZE;
|
|
30
|
+
const wouldExceedCount = currentBatch.length >= CLOUDWATCH_MAX_BATCH_COUNT;
|
|
31
|
+
// start new batch if limits exceeded
|
|
32
|
+
if (currentBatch.length > 0 && (wouldExceedSize || wouldExceedCount)) {
|
|
33
|
+
batches.push(currentBatch);
|
|
34
|
+
currentBatch = [];
|
|
35
|
+
currentBatchSize = 0;
|
|
36
|
+
}
|
|
37
|
+
currentBatch.push(event);
|
|
38
|
+
currentBatchSize += eventSize;
|
|
39
|
+
}
|
|
40
|
+
// push final batch if non-empty
|
|
41
|
+
if (currentBatch.length > 0) {
|
|
42
|
+
batches.push(currentBatch);
|
|
43
|
+
}
|
|
44
|
+
return batches;
|
|
45
|
+
};
|
|
46
|
+
exports.asCloudWatchBatches = asCloudWatchBatches;
|
|
47
|
+
//# sourceMappingURL=asCloudWatchBatches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asCloudWatchBatches.js","sourceRoot":"","sources":["../../../../src/domain.operations/outlets/cloudwatch/asCloudWatchBatches.ts"],"names":[],"mappings":";;;AAEA,+DAA4D;AAE5D;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,OAAS,CAAC,CAAC,MAAM;AACnD,MAAM,0BAA0B,GAAG,KAAM,CAAC;AAC1C,MAAM,yBAAyB,GAAG,EAAE,CAAC,CAAC,kBAAkB;AAExD;;;;;GAKG;AACI,MAAM,mBAAmB,GAAG,CAAC,MAAkB,EAAgB,EAAE;IACtE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnC,MAAM,OAAO,GAAiB,EAAE,CAAC;IACjC,IAAI,YAAY,GAAe,EAAE,CAAC;IAClC,IAAI,gBAAgB,GAAG,CAAC,CAAC;IAEzB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,IAAA,yCAAmB,EAAC,KAAK,CAAC,GAAG,yBAAyB,CAAC;QAEzE,2CAA2C;QAC3C,MAAM,eAAe,GACnB,gBAAgB,GAAG,SAAS,GAAG,yBAAyB,CAAC;QAC3D,MAAM,gBAAgB,GAAG,YAAY,CAAC,MAAM,IAAI,0BAA0B,CAAC;QAE3E,qCAAqC;QACrC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,eAAe,IAAI,gBAAgB,CAAC,EAAE,CAAC;YACrE,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC3B,YAAY,GAAG,EAAE,CAAC;YAClB,gBAAgB,GAAG,CAAC,CAAC;QACvB,CAAC;QAED,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,gBAAgB,IAAI,SAAS,CAAC;IAChC,CAAC;IAED,gCAAgC;IAChC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAhCW,QAAA,mBAAmB,uBAgC9B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LogEvent } from '../../../domain.objects/LogOutlet';
|
|
2
|
+
/**
|
|
3
|
+
* .what = transforms LogEvents to CloudWatch PutLogEvents format
|
|
4
|
+
* .why = extracts decode-friction from orchestrator
|
|
5
|
+
*/
|
|
6
|
+
export declare const asCloudWatchLogEvents: (events: LogEvent[]) => Array<{
|
|
7
|
+
timestamp: number;
|
|
8
|
+
message: string;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asCloudWatchLogEvents = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = transforms LogEvents to CloudWatch PutLogEvents format
|
|
6
|
+
* .why = extracts decode-friction from orchestrator
|
|
7
|
+
*/
|
|
8
|
+
const asCloudWatchLogEvents = (events) => {
|
|
9
|
+
return events.map((e) => ({
|
|
10
|
+
timestamp: Date.parse(e.timestamp),
|
|
11
|
+
message: JSON.stringify(e),
|
|
12
|
+
}));
|
|
13
|
+
};
|
|
14
|
+
exports.asCloudWatchLogEvents = asCloudWatchLogEvents;
|
|
15
|
+
//# sourceMappingURL=asCloudWatchLogEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asCloudWatchLogEvents.js","sourceRoot":"","sources":["../../../../src/domain.operations/outlets/cloudwatch/asCloudWatchLogEvents.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CACnC,MAAkB,EAC6B,EAAE;IACjD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACxB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QAClC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;KAC3B,CAAC,CAAC,CAAC;AACN,CAAC,CAAC;AAPW,QAAA,qBAAqB,yBAOhC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = generates a default log stream name for CloudWatch
|
|
3
|
+
* .why = matches Lambda's log stream format: YYYY/MM/DD/[$LATEST]instance-id
|
|
4
|
+
* .note = explicit opt-in: user adds outlet only when automatic forwarder absent
|
|
5
|
+
*/
|
|
6
|
+
export declare const asDefaultLogStreamName: () => string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asDefaultLogStreamName = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
/**
|
|
6
|
+
* .what = extracts date in Lambda log stream format (YYYY/MM/DD)
|
|
7
|
+
* .why = matches Lambda's native log stream date format
|
|
8
|
+
*/
|
|
9
|
+
const asLambdaDatePrefix = (input) => {
|
|
10
|
+
const iso = input.from.toISOString().split('T')[0];
|
|
11
|
+
return iso.replace(/-/g, '/'); // YYYY-MM-DD -> YYYY/MM/DD
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* .what = generates a default log stream name for CloudWatch
|
|
15
|
+
* .why = matches Lambda's log stream format: YYYY/MM/DD/[$LATEST]instance-id
|
|
16
|
+
* .note = explicit opt-in: user adds outlet only when automatic forwarder absent
|
|
17
|
+
*/
|
|
18
|
+
const asDefaultLogStreamName = () => {
|
|
19
|
+
const datePrefix = asLambdaDatePrefix({ from: new Date() });
|
|
20
|
+
const instanceId = (0, crypto_1.randomUUID)();
|
|
21
|
+
return `${datePrefix}/[$LATEST]${instanceId}`;
|
|
22
|
+
};
|
|
23
|
+
exports.asDefaultLogStreamName = asDefaultLogStreamName;
|
|
24
|
+
//# sourceMappingURL=asDefaultLogStreamName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asDefaultLogStreamName.js","sourceRoot":"","sources":["../../../../src/domain.operations/outlets/cloudwatch/asDefaultLogStreamName.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC;;;GAGG;AACH,MAAM,kBAAkB,GAAG,CAAC,KAAqB,EAAU,EAAE;IAC3D,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;IACpD,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,2BAA2B;AAC5D,CAAC,CAAC;AAEF;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,GAAW,EAAE;IACjD,MAAM,UAAU,GAAG,kBAAkB,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,IAAA,mBAAU,GAAE,CAAC;IAChC,OAAO,GAAG,UAAU,aAAa,UAAU,EAAE,CAAC;AAChD,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = generates a lambda-style log group name
|
|
3
|
+
* .why = CloudWatch log groups follow `/aws/lambda/{service}-{env}` pattern
|
|
4
|
+
*
|
|
5
|
+
* .note = performs I/O when service is not provided:
|
|
6
|
+
* - reads package.json from cwd for service name
|
|
7
|
+
* - reads env vars (ENVIRONMENT_ACCESS, ENV_ACCESS, STAGE, NODE_ENV) for env.access
|
|
8
|
+
* for pure usage, pass both service and env.access explicitly.
|
|
9
|
+
*
|
|
10
|
+
* @param service - service name (default: reads from package.json)
|
|
11
|
+
* @param env.access - environment access level (default: from env vars, fallback 'local')
|
|
12
|
+
*/
|
|
13
|
+
export declare const asLambdaStyleLogGroupName: ({ service, env, }?: {
|
|
14
|
+
service?: string;
|
|
15
|
+
env?: {
|
|
16
|
+
access?: string;
|
|
17
|
+
};
|
|
18
|
+
}) => string;
|