sdk-logs 0.6.12
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/LogTrail.d.ts +20 -0
- package/dist/domain.objects/LogTrail.js +3 -0
- package/dist/domain.objects/LogTrail.js.map +1 -0
- package/dist/domain.objects/constants.d.ts +35 -0
- package/dist/domain.objects/constants.js +42 -0
- package/dist/domain.objects/constants.js.map +1 -0
- package/dist/domain.operations/formatLogContentsForEnvironment.d.ts +17 -0
- package/dist/domain.operations/formatLogContentsForEnvironment.js +39 -0
- package/dist/domain.operations/formatLogContentsForEnvironment.js.map +1 -0
- package/dist/domain.operations/generateLogMethod.d.ts +6 -0
- package/dist/domain.operations/generateLogMethod.js +37 -0
- package/dist/domain.operations/generateLogMethod.js.map +1 -0
- package/dist/domain.operations/generateLogMethods.d.ts +36 -0
- package/dist/domain.operations/generateLogMethods.js +22 -0
- package/dist/domain.operations/generateLogMethods.js.map +1 -0
- package/dist/domain.operations/getRecommendedMinimalLogLevelForEnvironment.d.ts +2 -0
- package/dist/domain.operations/getRecommendedMinimalLogLevelForEnvironment.js +38 -0
- package/dist/domain.operations/getRecommendedMinimalLogLevelForEnvironment.js.map +1 -0
- package/dist/domain.operations/identifyEnvironment.d.ts +6 -0
- package/dist/domain.operations/identifyEnvironment.js +22 -0
- package/dist/domain.operations/identifyEnvironment.js.map +1 -0
- package/dist/domain.operations/withLogTrail.d.ts +52 -0
- package/dist/domain.operations/withLogTrail.js +146 -0
- package/dist/domain.operations/withLogTrail.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/license.md +21 -0
- package/package.json +103 -0
- package/readme.md +45 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Procedure, ProcedureContext } from 'domain-glossary-procedure';
|
|
2
|
+
import type { LogMethods } from '../domain.operations/generateLogMethods';
|
|
3
|
+
/**
|
|
4
|
+
* .what = the procedure invocation trail
|
|
5
|
+
*/
|
|
6
|
+
export type LogTrail = string[];
|
|
7
|
+
export interface ContextLogTrail {
|
|
8
|
+
/**
|
|
9
|
+
* .what = the log context which can be used; methods, trail, etc
|
|
10
|
+
*/
|
|
11
|
+
log: LogMethods & {
|
|
12
|
+
_orig?: LogMethods;
|
|
13
|
+
} & {
|
|
14
|
+
/**
|
|
15
|
+
* .what = the log trail which has been collected
|
|
16
|
+
*/
|
|
17
|
+
trail?: LogTrail;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export type HasContextLogTrail<T extends Procedure> = ProcedureContext<T> extends ContextLogTrail ? T : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogTrail.js","sourceRoot":"","sources":["../../src/domain.objects/LogTrail.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* define the supported log levels
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
ERROR = "error",
|
|
6
|
+
WARN = "warn",
|
|
7
|
+
INFO = "info",
|
|
8
|
+
DEBUG = "debug"
|
|
9
|
+
}
|
|
10
|
+
export declare const isOfLogLevel: import("type-fns").AssessWithAssure<string | number | symbol, LogLevel>;
|
|
11
|
+
/**
|
|
12
|
+
* define specifically supported environments
|
|
13
|
+
*/
|
|
14
|
+
export declare enum SupportedEnvironment {
|
|
15
|
+
/**
|
|
16
|
+
* the local environment balances information -vs- oversharing
|
|
17
|
+
* - metadata is stringified to not cause too much visual "noise" in the console
|
|
18
|
+
* - log level should default to being conservatively balanced, to reduce noise in the console
|
|
19
|
+
* - especially when considering the ease of retrying requests with more permissive log-level specified
|
|
20
|
+
*/
|
|
21
|
+
LOCAL = "LOCAL",
|
|
22
|
+
/**
|
|
23
|
+
* the aws environment has a few extra considerations for logging
|
|
24
|
+
* - metadata should not be json-stringified, and should be simply nested instead for cloudwatch insights parsing
|
|
25
|
+
* - log level should default to be more permissive, as cloudwatch costs are low enough to be worth the increased visibility in most cases
|
|
26
|
+
*/
|
|
27
|
+
AWS_LAMBDA = "AWS_LAMBDA",
|
|
28
|
+
/**
|
|
29
|
+
* the web browser environment allows us to focus on accessibility of information
|
|
30
|
+
* - the metadata should not be json-stringified. instead, it should be simply nested for devtools console accessibility
|
|
31
|
+
* - log level should default to being conservatively balanced, to reduce noise in the console
|
|
32
|
+
* - especially when considering the ease of retrying requests with more permissive log-level specified
|
|
33
|
+
*/
|
|
34
|
+
WEB_BROWSER = "WEB_BROWSER"
|
|
35
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SupportedEnvironment = exports.isOfLogLevel = exports.LogLevel = void 0;
|
|
4
|
+
const type_fns_1 = require("type-fns");
|
|
5
|
+
/**
|
|
6
|
+
* define the supported log levels
|
|
7
|
+
*/
|
|
8
|
+
var LogLevel;
|
|
9
|
+
(function (LogLevel) {
|
|
10
|
+
LogLevel["ERROR"] = "error";
|
|
11
|
+
LogLevel["WARN"] = "warn";
|
|
12
|
+
LogLevel["INFO"] = "info";
|
|
13
|
+
LogLevel["DEBUG"] = "debug";
|
|
14
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
15
|
+
exports.isOfLogLevel = (0, type_fns_1.createIsOfEnum)(LogLevel);
|
|
16
|
+
/**
|
|
17
|
+
* define specifically supported environments
|
|
18
|
+
*/
|
|
19
|
+
var SupportedEnvironment;
|
|
20
|
+
(function (SupportedEnvironment) {
|
|
21
|
+
/**
|
|
22
|
+
* the local environment balances information -vs- oversharing
|
|
23
|
+
* - metadata is stringified to not cause too much visual "noise" in the console
|
|
24
|
+
* - log level should default to being conservatively balanced, to reduce noise in the console
|
|
25
|
+
* - especially when considering the ease of retrying requests with more permissive log-level specified
|
|
26
|
+
*/
|
|
27
|
+
SupportedEnvironment["LOCAL"] = "LOCAL";
|
|
28
|
+
/**
|
|
29
|
+
* the aws environment has a few extra considerations for logging
|
|
30
|
+
* - metadata should not be json-stringified, and should be simply nested instead for cloudwatch insights parsing
|
|
31
|
+
* - log level should default to be more permissive, as cloudwatch costs are low enough to be worth the increased visibility in most cases
|
|
32
|
+
*/
|
|
33
|
+
SupportedEnvironment["AWS_LAMBDA"] = "AWS_LAMBDA";
|
|
34
|
+
/**
|
|
35
|
+
* the web browser environment allows us to focus on accessibility of information
|
|
36
|
+
* - the metadata should not be json-stringified. instead, it should be simply nested for devtools console accessibility
|
|
37
|
+
* - log level should default to being conservatively balanced, to reduce noise in the console
|
|
38
|
+
* - especially when considering the ease of retrying requests with more permissive log-level specified
|
|
39
|
+
*/
|
|
40
|
+
SupportedEnvironment["WEB_BROWSER"] = "WEB_BROWSER";
|
|
41
|
+
})(SupportedEnvironment || (exports.SupportedEnvironment = SupportedEnvironment = {}));
|
|
42
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/domain.objects/constants.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAE1C;;GAEG;AACH,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB;AACY,QAAA,YAAY,GAAG,IAAA,yBAAc,EAAC,QAAQ,CAAC,CAAC;AAErD;;GAEG;AACH,IAAY,oBAuBX;AAvBD,WAAY,oBAAoB;IAC9B;;;;;OAKG;IACH,uCAAe,CAAA;IAEf;;;;OAIG;IACH,iDAAyB,CAAA;IAEzB;;;;;OAKG;IACH,mDAA2B,CAAA;AAC7B,CAAC,EAvBW,oBAAoB,oCAApB,oBAAoB,QAuB/B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type LogLevel } from '../domain.objects/constants';
|
|
2
|
+
export declare const formatLogContentsForEnvironment: ({ level, timestamp, message, metadata, }: {
|
|
3
|
+
level: LogLevel;
|
|
4
|
+
timestamp: string;
|
|
5
|
+
message: string;
|
|
6
|
+
metadata?: Record<string, any>;
|
|
7
|
+
}) => string | {
|
|
8
|
+
level: LogLevel;
|
|
9
|
+
timestamp: string;
|
|
10
|
+
message: string;
|
|
11
|
+
metadata: string;
|
|
12
|
+
} | {
|
|
13
|
+
level: LogLevel;
|
|
14
|
+
timestamp: string;
|
|
15
|
+
message: string;
|
|
16
|
+
metadata: Record<string, any> | undefined;
|
|
17
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatLogContentsForEnvironment = void 0;
|
|
4
|
+
const constants_1 = require("../domain.objects/constants");
|
|
5
|
+
const identifyEnvironment_1 = require("./identifyEnvironment");
|
|
6
|
+
const formatLogContentsForEnvironment = ({ level, timestamp, message, metadata, }) => {
|
|
7
|
+
const env = (0, identifyEnvironment_1.identifyEnvironment)();
|
|
8
|
+
// if its a "local" environment, then dont stringify the contents - but stringify the metadata to cut down on visual noise
|
|
9
|
+
if (env === constants_1.SupportedEnvironment.LOCAL) {
|
|
10
|
+
return {
|
|
11
|
+
level,
|
|
12
|
+
timestamp,
|
|
13
|
+
message,
|
|
14
|
+
metadata: JSON.stringify(metadata), // json stringify it to cut down on the visual noise in the console
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
// 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 (env === constants_1.SupportedEnvironment.AWS_LAMBDA) {
|
|
19
|
+
return JSON.stringify({
|
|
20
|
+
level,
|
|
21
|
+
timestamp,
|
|
22
|
+
message,
|
|
23
|
+
metadata,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
// 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 (env === constants_1.SupportedEnvironment.WEB_BROWSER) {
|
|
28
|
+
return {
|
|
29
|
+
level,
|
|
30
|
+
timestamp,
|
|
31
|
+
message,
|
|
32
|
+
metadata,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// if it was not one of the above, we have not supported this environment yet
|
|
36
|
+
throw new Error('unsupported environment detected. this should never occur - and is a bug within sdk-logs'); // fail fast
|
|
37
|
+
};
|
|
38
|
+
exports.formatLogContentsForEnvironment = formatLogContentsForEnvironment;
|
|
39
|
+
//# sourceMappingURL=formatLogContentsForEnvironment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatLogContentsForEnvironment.js","sourceRoot":"","sources":["../../src/domain.operations/formatLogContentsForEnvironment.ts"],"names":[],"mappings":";;;AAAA,6DAGuC;AAEvC,+DAA4D;AAErD,MAAM,+BAA+B,GAAG,CAAC,EAC9C,KAAK,EACL,SAAS,EACT,OAAO,EACP,QAAQ,GAMT,EAAE,EAAE;IACH,MAAM,GAAG,GAAG,IAAA,yCAAmB,GAAE,CAAC;IAElC,0HAA0H;IAC1H,IAAI,GAAG,KAAK,gCAAoB,CAAC,KAAK,EAAE,CAAC;QACvC,OAAO;YACL,KAAK;YACL,SAAS;YACT,OAAO;YACP,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mEAAmE;SACxG,CAAC;IACJ,CAAC;IAED,qKAAqK;IACrK,IAAI,GAAG,KAAK,gCAAoB,CAAC,UAAU,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,KAAK;YACL,SAAS;YACT,OAAO;YACP,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAED,wJAAwJ;IACxJ,IAAI,GAAG,KAAK,gCAAoB,CAAC,WAAW,EAAE,CAAC;QAC7C,OAAO;YACL,KAAK;YACL,SAAS;YACT,OAAO;YACP,QAAQ;SACT,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,CAAC,CAAC,YAAY;AACjB,CAAC,CAAC;AA/CW,QAAA,+BAA+B,mCA+C1C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LogLevel } from '../domain.objects/constants';
|
|
2
|
+
export type LogMethod = (message: string, metadata?: any) => void;
|
|
3
|
+
export declare const generateLogMethod: ({ level, minimalLogLevel, }: {
|
|
4
|
+
level: LogLevel;
|
|
5
|
+
minimalLogLevel: LogLevel;
|
|
6
|
+
}) => (message: string, metadata?: object) => void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateLogMethod = void 0;
|
|
4
|
+
const constants_1 = require("../domain.objects/constants");
|
|
5
|
+
const formatLogContentsForEnvironment_1 = require("./formatLogContentsForEnvironment");
|
|
6
|
+
/*
|
|
7
|
+
define priority order of log levels and make it easy to ask questions about
|
|
8
|
+
*/
|
|
9
|
+
const logLevelPriorityOrder = [
|
|
10
|
+
constants_1.LogLevel.ERROR,
|
|
11
|
+
constants_1.LogLevel.WARN,
|
|
12
|
+
constants_1.LogLevel.INFO,
|
|
13
|
+
constants_1.LogLevel.DEBUG,
|
|
14
|
+
];
|
|
15
|
+
const aIsEqualOrMoreImportantThanB = ({ a, b }) => logLevelPriorityOrder.indexOf(a) - logLevelPriorityOrder.indexOf(b) <= 0;
|
|
16
|
+
const generateLogMethod = ({ level, minimalLogLevel, }) => {
|
|
17
|
+
return (message, metadata) => {
|
|
18
|
+
if (aIsEqualOrMoreImportantThanB({ a: level, b: minimalLogLevel })) {
|
|
19
|
+
// determine the console level (i.e., use warn if we can to make the logs stand out more)
|
|
20
|
+
const consoleMethod = aIsEqualOrMoreImportantThanB({
|
|
21
|
+
a: level,
|
|
22
|
+
b: constants_1.LogLevel.WARN,
|
|
23
|
+
})
|
|
24
|
+
? console.warn
|
|
25
|
+
: console.log; // tslint:disable-line no-console
|
|
26
|
+
// output the message to console, which will get picked up by cloudwatch when deployed lambda is invoked
|
|
27
|
+
consoleMethod((0, formatLogContentsForEnvironment_1.formatLogContentsForEnvironment)({
|
|
28
|
+
level,
|
|
29
|
+
timestamp: new Date().toISOString(),
|
|
30
|
+
message,
|
|
31
|
+
metadata,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.generateLogMethod = generateLogMethod;
|
|
37
|
+
//# sourceMappingURL=generateLogMethod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateLogMethod.js","sourceRoot":"","sources":["../../src/domain.operations/generateLogMethod.ts"],"names":[],"mappings":";;;AAAA,6DAAyD;AAEzD,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,GAIhB,EAAE,EAAE;IACH,OAAO,CAAC,OAAe,EAAE,QAAiB,EAAE,EAAE;QAC5C,IAAI,4BAA4B,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;YACnE,yFAAyF;YACzF,MAAM,aAAa,GAAG,4BAA4B,CAAC;gBACjD,CAAC,EAAE,KAAK;gBACR,CAAC,EAAE,oBAAQ,CAAC,IAAI;aACjB,CAAC;gBACA,CAAC,CAAC,OAAO,CAAC,IAAI;gBACd,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,iCAAiC;YAElD,wGAAwG;YACxG,aAAa,CACX,IAAA,iEAA+B,EAAC;gBAC9B,KAAK;gBACL,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,OAAO;gBACP,QAAQ;aACT,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AA5BW,QAAA,iBAAiB,qBA4B5B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LogLevel } from '../domain.objects/constants';
|
|
2
|
+
import { type LogMethod } from './generateLogMethod';
|
|
3
|
+
export interface LogMethods {
|
|
4
|
+
/**
|
|
5
|
+
* `error` level logs are used to indicate a critical and urgent failure that requires immediate resolution
|
|
6
|
+
* - these logs are often associated with someone on-call being notified immediately, regardless of the time or day
|
|
7
|
+
* - when choosing to log something with a log level of "error", you are saying that someone should be woken up in the middle of the night if this occurs
|
|
8
|
+
*/
|
|
9
|
+
error: LogMethod;
|
|
10
|
+
/**
|
|
11
|
+
* `warn` level logs are used to indicate that something is going wrong, but can wait to be resolved until a convenient time
|
|
12
|
+
* - these logs are often associated with someone following up on them during business hours
|
|
13
|
+
* - when choosing to log something with a log level of "warn", you are saying that someone should look at this as soon as reasonably possible
|
|
14
|
+
*/
|
|
15
|
+
warn: LogMethod;
|
|
16
|
+
/**
|
|
17
|
+
* `info` level logs are used to indicate an interesting event that should be kept track of
|
|
18
|
+
* - these logs are often associated with health metrics, dashboard statistics, or custom log queries for investigations or reporting
|
|
19
|
+
* - when choosing to log something with a log level of "info", you are saying that someone will be interested in this information indefinitely
|
|
20
|
+
*/
|
|
21
|
+
info: LogMethod;
|
|
22
|
+
/**
|
|
23
|
+
* `debug` level logs are used to output information that can aid users in tracking down bugs or confirming that things are working as expected
|
|
24
|
+
* - these logs are often associated with common actions that happen within code, that may only be relevant when debugging your applications
|
|
25
|
+
* - 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
|
+
debug: LogMethod;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* define how to generate the log methods
|
|
31
|
+
* - allows you to specify the minimal log level to use for your application
|
|
32
|
+
* - defaults to recommended levels for the environment
|
|
33
|
+
*/
|
|
34
|
+
export declare const generateLogMethods: ({ minimalLogLevel, }?: {
|
|
35
|
+
minimalLogLevel?: LogLevel;
|
|
36
|
+
}) => LogMethods;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateLogMethods = 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
|
+
*/
|
|
12
|
+
const generateLogMethods = ({ minimalLogLevel = (0, getRecommendedMinimalLogLevelForEnvironment_1.getRecommendedMinimalLogLevelForEnvironment)(), } = {}) => {
|
|
13
|
+
// generate the methods
|
|
14
|
+
return {
|
|
15
|
+
error: (0, generateLogMethod_1.generateLogMethod)({ level: constants_1.LogLevel.ERROR, minimalLogLevel }),
|
|
16
|
+
warn: (0, generateLogMethod_1.generateLogMethod)({ level: constants_1.LogLevel.WARN, minimalLogLevel }),
|
|
17
|
+
info: (0, generateLogMethod_1.generateLogMethod)({ level: constants_1.LogLevel.INFO, minimalLogLevel }),
|
|
18
|
+
debug: (0, generateLogMethod_1.generateLogMethod)({ level: constants_1.LogLevel.DEBUG, minimalLogLevel }),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.generateLogMethods = generateLogMethods;
|
|
22
|
+
//# sourceMappingURL=generateLogMethods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateLogMethods.js","sourceRoot":"","sources":["../../src/domain.operations/generateLogMethods.ts"],"names":[],"mappings":";;;AAAA,6DAAyD;AAEzD,2DAAwE;AACxE,+GAA4G;AAgC5G;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,CAAC,EACjC,eAAe,GAAG,IAAA,yFAA2C,GAAE,MAG7D,EAAE,EAAc,EAAE;IACpB,uBAAuB;IACvB,OAAO;QACL,KAAK,EAAE,IAAA,qCAAiB,EAAC,EAAE,KAAK,EAAE,oBAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC;QACpE,IAAI,EAAE,IAAA,qCAAiB,EAAC,EAAE,KAAK,EAAE,oBAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,CAAC;QAClE,IAAI,EAAE,IAAA,qCAAiB,EAAC,EAAE,KAAK,EAAE,oBAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,CAAC;QAClE,KAAK,EAAE,IAAA,qCAAiB,EAAC,EAAE,KAAK,EAAE,oBAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC;KACrE,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,kBAAkB,sBAY7B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRecommendedMinimalLogLevelForEnvironment = void 0;
|
|
4
|
+
const constants_1 = require("../domain.objects/constants");
|
|
5
|
+
const identifyEnvironment_1 = require("./identifyEnvironment");
|
|
6
|
+
const getLogLevelFromEnvVar = () => {
|
|
7
|
+
// if LOG_LEVEL was specified, use that
|
|
8
|
+
const logLevelEnvVar = process.env.LOG_LEVEL || null; // cast falsy values to null
|
|
9
|
+
if (logLevelEnvVar) {
|
|
10
|
+
// if the log level is valid, use it
|
|
11
|
+
if ((0, constants_1.isOfLogLevel)(logLevelEnvVar))
|
|
12
|
+
return logLevelEnvVar;
|
|
13
|
+
// otherwise, warn and continue to attempt other options
|
|
14
|
+
console.warn(`environmental variable LOG_LEVEL was set to an invalid value: '${logLevelEnvVar}'. using the default instead`);
|
|
15
|
+
}
|
|
16
|
+
// if LOG_DEBUG was specified as true, use that (it's a common intuitive alias)
|
|
17
|
+
const logDebugEnvVar = process.env.LOG_DEBUG || null;
|
|
18
|
+
if (logDebugEnvVar === 'true')
|
|
19
|
+
return constants_1.LogLevel.DEBUG;
|
|
20
|
+
// todo: consider supporting other LOG_${level} options
|
|
21
|
+
// otherwise, null
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
const getRecommendedMinimalLogLevelForEnvironment = () => {
|
|
25
|
+
// if the LOG_LEVEL env var is defined, then use what is specified by that
|
|
26
|
+
const logLevelFromEnvVar = getLogLevelFromEnvVar();
|
|
27
|
+
if (logLevelFromEnvVar)
|
|
28
|
+
return logLevelFromEnvVar;
|
|
29
|
+
// identify the env we're in
|
|
30
|
+
const env = (0, identifyEnvironment_1.identifyEnvironment)();
|
|
31
|
+
// if we're in aws lambda env, then default to DEBUG - since cloudwatch costs are cheap and extra visibility is worth it in most cases
|
|
32
|
+
if (env === constants_1.SupportedEnvironment.AWS_LAMBDA)
|
|
33
|
+
return constants_1.LogLevel.DEBUG;
|
|
34
|
+
// otherwise, default to INFO - to balance signal -vs- noise
|
|
35
|
+
return constants_1.LogLevel.INFO;
|
|
36
|
+
};
|
|
37
|
+
exports.getRecommendedMinimalLogLevelForEnvironment = getRecommendedMinimalLogLevelForEnvironment;
|
|
38
|
+
//# sourceMappingURL=getRecommendedMinimalLogLevelForEnvironment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRecommendedMinimalLogLevelForEnvironment.js","sourceRoot":"","sources":["../../src/domain.operations/getRecommendedMinimalLogLevelForEnvironment.ts"],"names":[],"mappings":";;;AAAA,6DAIuC;AAEvC,+DAA4D;AAE5D,MAAM,qBAAqB,GAAG,GAAoB,EAAE;IAClD,uCAAuC;IACvC,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,4BAA4B;IAClF,IAAI,cAAc,EAAE,CAAC;QACnB,oCAAoC;QACpC,IAAI,IAAA,wBAAY,EAAC,cAAc,CAAC;YAAE,OAAO,cAAc,CAAC;QAExD,wDAAwD;QACxD,OAAO,CAAC,IAAI,CACV,kEAAkE,cAAc,8BAA8B,CAC/G,CAAC;IACJ,CAAC;IAED,+EAA+E;IAC/E,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,IAAI,CAAC;IACrD,IAAI,cAAc,KAAK,MAAM;QAAE,OAAO,oBAAQ,CAAC,KAAK,CAAC;IAErD,uDAAuD;IAEvD,kBAAkB;IAClB,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEK,MAAM,2CAA2C,GAAG,GAAa,EAAE;IACxE,0EAA0E;IAC1E,MAAM,kBAAkB,GAAG,qBAAqB,EAAE,CAAC;IACnD,IAAI,kBAAkB;QAAE,OAAO,kBAAkB,CAAC;IAElD,4BAA4B;IAC5B,MAAM,GAAG,GAAG,IAAA,yCAAmB,GAAE,CAAC;IAElC,sIAAsI;IACtI,IAAI,GAAG,KAAK,gCAAoB,CAAC,UAAU;QAAE,OAAO,oBAAQ,CAAC,KAAK,CAAC;IAEnE,4DAA4D;IAC5D,OAAO,oBAAQ,CAAC,IAAI,CAAC;AACvB,CAAC,CAAC;AAbW,QAAA,2CAA2C,+CAatD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SupportedEnvironment } from '../domain.objects/constants';
|
|
2
|
+
/**
|
|
3
|
+
* identifies the supported environment that this is being run in, as best as possible
|
|
4
|
+
* - defaults to LOCAL environment, as it has the most common settings and is not distinguishable otherwise
|
|
5
|
+
*/
|
|
6
|
+
export declare const identifyEnvironment: () => SupportedEnvironment;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.identifyEnvironment = void 0;
|
|
4
|
+
const constants_1 = require("../domain.objects/constants");
|
|
5
|
+
/**
|
|
6
|
+
* identifies the supported environment that this is being run in, as best as possible
|
|
7
|
+
* - defaults to LOCAL environment, as it has the most common settings and is not distinguishable otherwise
|
|
8
|
+
*/
|
|
9
|
+
const identifyEnvironment = () => {
|
|
10
|
+
// check if its an aws-lambda runtime environment
|
|
11
|
+
const isAwsLambdaEnvironment = !!process.env.AWS_LAMBDA_FUNCTION_NAME; // if this env var is defined, then its aws lambda env
|
|
12
|
+
if (isAwsLambdaEnvironment)
|
|
13
|
+
return constants_1.SupportedEnvironment.AWS_LAMBDA;
|
|
14
|
+
// check if its a browser environment
|
|
15
|
+
const isWebBrowserEnvironment = typeof window !== 'undefined' && typeof window.document !== 'undefined'; // if both are defined, then its a browser
|
|
16
|
+
if (isWebBrowserEnvironment)
|
|
17
|
+
return constants_1.SupportedEnvironment.WEB_BROWSER;
|
|
18
|
+
// default to local env
|
|
19
|
+
return constants_1.SupportedEnvironment.LOCAL;
|
|
20
|
+
};
|
|
21
|
+
exports.identifyEnvironment = identifyEnvironment;
|
|
22
|
+
//# sourceMappingURL=identifyEnvironment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifyEnvironment.js","sourceRoot":"","sources":["../../src/domain.operations/identifyEnvironment.ts"],"names":[],"mappings":";;;AAAA,6DAAqE;AAErE;;;GAGG;AACI,MAAM,mBAAmB,GAAG,GAAyB,EAAE;IAC5D,iDAAiD;IACjD,MAAM,sBAAsB,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,sDAAsD;IAC7H,IAAI,sBAAsB;QAAE,OAAO,gCAAoB,CAAC,UAAU,CAAC;IAEnE,qCAAqC;IACrC,MAAM,uBAAuB,GAC3B,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW,CAAC,CAAC,0CAA0C;IACrH,IAAI,uBAAuB;QAAE,OAAO,gCAAoB,CAAC,WAAW,CAAC;IAErE,uBAAuB;IACvB,OAAO,gCAAoB,CAAC,KAAK,CAAC;AACpC,CAAC,CAAC;AAZW,QAAA,mBAAmB,uBAY9B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type IsoDuration } from 'iso-time';
|
|
2
|
+
import type { LogLevel } from '../domain.objects/constants';
|
|
3
|
+
import type { ContextLogTrail } from '../domain.objects/LogTrail';
|
|
4
|
+
/**
|
|
5
|
+
* enables input output logging and tracing for a method
|
|
6
|
+
*
|
|
7
|
+
* todo: - add tracing identifier w/ async-context
|
|
8
|
+
* todo: - hookup visual tracing w/ external lib (vi...lo...)
|
|
9
|
+
* todo: - bundle this with its own logging library which supports scoped logs
|
|
10
|
+
*/
|
|
11
|
+
export declare const withLogTrail: <TInput, TContext extends ContextLogTrail, TOutput>(logic: (input: TInput, context: TContext) => TOutput, { name: declaredName, log: logOptions, duration, }: {
|
|
12
|
+
/**
|
|
13
|
+
* specifies the name of the function, if the function does not have a name assigned already
|
|
14
|
+
*/
|
|
15
|
+
name?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* enable redacting parts of the input or output from logging
|
|
18
|
+
*/
|
|
19
|
+
log?: {
|
|
20
|
+
/**
|
|
21
|
+
* specifies the level to log the trail with
|
|
22
|
+
*
|
|
23
|
+
* note:
|
|
24
|
+
* - defaults input & output logs to level .debug // todo: debug to .trail
|
|
25
|
+
* - defaults error logs to level .warn
|
|
26
|
+
* - error level is only overridable via the object form (to prevent accidental downgrade of error logs)
|
|
27
|
+
*/
|
|
28
|
+
level?: LogLevel | {
|
|
29
|
+
input?: LogLevel | undefined;
|
|
30
|
+
output?: LogLevel | undefined;
|
|
31
|
+
error?: LogLevel | undefined;
|
|
32
|
+
} | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* what of the input to log
|
|
35
|
+
*/
|
|
36
|
+
input?: ((input: TInput, context: TContext) => any) | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* what of the output to log
|
|
39
|
+
*/
|
|
40
|
+
output?: ((value: Awaited<TOutput>) => any) | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* what of the error to log
|
|
43
|
+
*/
|
|
44
|
+
error?: ((error: Error) => any) | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* specifies the threshold after which a duration will be included on the output log
|
|
48
|
+
*/
|
|
49
|
+
duration?: {
|
|
50
|
+
threshold: IsoDuration;
|
|
51
|
+
} | undefined;
|
|
52
|
+
}) => (input: TInput, context: TContext) => TOutput;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withLogTrail = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const iso_time_1 = require("iso-time");
|
|
6
|
+
const type_fns_1 = require("type-fns");
|
|
7
|
+
const noOp = (...input) => input;
|
|
8
|
+
const omitContext = (...input) => input[0]; // standard pattern for args = [input, context]
|
|
9
|
+
const pickErrorMessage = (input) => ({
|
|
10
|
+
error: { message: input.message },
|
|
11
|
+
});
|
|
12
|
+
const roundToHundredths = (num) => Math.round(num * 100) / 100; // https://stackoverflow.com/a/14968691/3068233
|
|
13
|
+
const DEFAULT_DURATION_REPORT_THRESHOLD = process.env
|
|
14
|
+
.VISUALOGIC_DURATION_THRESHOLD
|
|
15
|
+
? parseInt(process.env.VISUALOGIC_DURATION_THRESHOLD)
|
|
16
|
+
: (0, iso_time_1.toMilliseconds)({ seconds: 1 });
|
|
17
|
+
/**
|
|
18
|
+
* enables input output logging and tracing for a method
|
|
19
|
+
*
|
|
20
|
+
* todo: - add tracing identifier w/ async-context
|
|
21
|
+
* todo: - hookup visual tracing w/ external lib (vi...lo...)
|
|
22
|
+
* todo: - bundle this with its own logging library which supports scoped logs
|
|
23
|
+
*/
|
|
24
|
+
const withLogTrail = (logic, { name: declaredName, log: logOptions, duration = {
|
|
25
|
+
threshold: { milliseconds: DEFAULT_DURATION_REPORT_THRESHOLD },
|
|
26
|
+
}, }) => {
|
|
27
|
+
// cache the name of the function per wrapping
|
|
28
|
+
const name = logic.name || declaredName || null; // use `\\` since `logic.name` returns `""` for anonymous functions
|
|
29
|
+
// if no name is identifiable, throw an error here to fail fast
|
|
30
|
+
if (!name)
|
|
31
|
+
throw new helpful_errors_1.UnexpectedCodePathError('could not identify name for wrapped function');
|
|
32
|
+
// if the name specified does not match the name of the function, throw an error here to fail fast
|
|
33
|
+
if (declaredName && name !== declaredName)
|
|
34
|
+
throw new helpful_errors_1.UnexpectedCodePathError('the natural name of the function is different than the declared name', { declaredName, naturalName: name });
|
|
35
|
+
// extract the log levels per operation
|
|
36
|
+
const logLevelInput = (typeof logOptions?.level === 'object'
|
|
37
|
+
? logOptions.level.input
|
|
38
|
+
: logOptions?.level) ?? 'debug';
|
|
39
|
+
const logLevelOutput = (typeof logOptions?.level === 'object'
|
|
40
|
+
? logOptions.level.output
|
|
41
|
+
: logOptions?.level) ?? 'debug';
|
|
42
|
+
const logLevelError =
|
|
43
|
+
// note: error level is only overridable via the object form, to prevent `level: 'info'` from accidentally downgrading error logs
|
|
44
|
+
(typeof logOptions?.level === 'object' ? logOptions.level.error : null) ??
|
|
45
|
+
'warn';
|
|
46
|
+
// extract the log methods
|
|
47
|
+
const logInputMethod = logOptions?.input ?? omitContext;
|
|
48
|
+
const logOutputMethod = logOptions?.output ?? noOp;
|
|
49
|
+
const logErrorMethod = logOptions?.error ?? pickErrorMessage;
|
|
50
|
+
// define the duration threshold
|
|
51
|
+
const durationReportingThreshold = duration.threshold;
|
|
52
|
+
const durationReportingThresholdInSeconds = (0, iso_time_1.toMilliseconds)(durationReportingThreshold) / 1000;
|
|
53
|
+
// wrap the function
|
|
54
|
+
return (input, context) => {
|
|
55
|
+
// now log the input
|
|
56
|
+
context.log[logLevelInput](`${name}.input`, {
|
|
57
|
+
input: logInputMethod(input, context),
|
|
58
|
+
});
|
|
59
|
+
// begin tracking duration
|
|
60
|
+
const startTimeInMilliseconds = new Date().getTime();
|
|
61
|
+
// define the context.log method that will be given to the logic
|
|
62
|
+
const logMethodsWithContext = {
|
|
63
|
+
// add the trail
|
|
64
|
+
trail: [...(context.log.trail ?? []), name],
|
|
65
|
+
// track the orig logger
|
|
66
|
+
_orig: context.log?._orig ?? context.log,
|
|
67
|
+
// add the scoped methods
|
|
68
|
+
debug: (message, metadata) => context.log.debug(`${name}.progress: ${message}`, metadata),
|
|
69
|
+
info: (message, metadata) => context.log.info(`${name}.progress: ${message}`, metadata),
|
|
70
|
+
warn: (message, metadata) => context.log.warn(`${name}.progress: ${message}`, metadata),
|
|
71
|
+
error: (message, metadata) => context.log.error(`${name}.progress: ${message}`, metadata),
|
|
72
|
+
};
|
|
73
|
+
// define what to do when we have an error
|
|
74
|
+
const logError = (error) => {
|
|
75
|
+
const endTimeInMilliseconds = new Date().getTime();
|
|
76
|
+
const durationInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
|
|
77
|
+
const durationInSeconds = roundToHundredths(durationInMilliseconds / 1e3); // https://stackoverflow.com/a/53970656/3068233
|
|
78
|
+
context.log[logLevelError](`${name}.error`, {
|
|
79
|
+
input: logInputMethod(input, context),
|
|
80
|
+
output: logErrorMethod(error),
|
|
81
|
+
...(durationInSeconds >= durationReportingThresholdInSeconds
|
|
82
|
+
? { duration: `${durationInSeconds} sec` } // only include the duration if the threshold was crossed
|
|
83
|
+
: {}),
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
// now execute the method, wrapped to catch sync errors
|
|
87
|
+
let result;
|
|
88
|
+
try {
|
|
89
|
+
result = logic(input, {
|
|
90
|
+
...context,
|
|
91
|
+
log: logMethodsWithContext,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
// log the error for sync functions that throw
|
|
96
|
+
if (error instanceof Error)
|
|
97
|
+
logError(error);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
// if the result was a promise, log when that method crosses the reporting threshold, to identify which procedures are slow
|
|
101
|
+
if ((0, type_fns_1.isAPromise)(result)) {
|
|
102
|
+
// define how to log the breach, on breach
|
|
103
|
+
const onDurationBreach = () => context.log[logLevelOutput](`${name}.duration.breach`, {
|
|
104
|
+
input: logInputMethod(input, context),
|
|
105
|
+
already: { duration: `${durationReportingThresholdInSeconds} sec` },
|
|
106
|
+
});
|
|
107
|
+
// define a timeout which will trigger on duration threshold
|
|
108
|
+
const onBreachTrigger = setTimeout(onDurationBreach, durationReportingThresholdInSeconds * 1000);
|
|
109
|
+
// remove the timeout when the operation completes, to prevent logging if completes before duration
|
|
110
|
+
void result
|
|
111
|
+
.finally(() => clearTimeout(onBreachTrigger))
|
|
112
|
+
.catch(() => {
|
|
113
|
+
// do nothing when there's an error; just catch it, to ensure it doesn't get propagated further as an uncaught exception
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// define what to do when we have output
|
|
117
|
+
const logOutput = (output) => {
|
|
118
|
+
const endTimeInMilliseconds = new Date().getTime();
|
|
119
|
+
const durationInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
|
|
120
|
+
const durationInSeconds = roundToHundredths(durationInMilliseconds / 1e3); // https://stackoverflow.com/a/53970656/3068233
|
|
121
|
+
context.log[logLevelOutput](`${name}.output`, {
|
|
122
|
+
input: logInputMethod(input, context),
|
|
123
|
+
output: logOutputMethod(output),
|
|
124
|
+
...(durationInSeconds >= durationReportingThresholdInSeconds
|
|
125
|
+
? { duration: `${durationInSeconds} sec` } // only include the duration if the threshold was crossed
|
|
126
|
+
: {}),
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
// if result is a promise, ensure we log after the output resolves
|
|
130
|
+
if ((0, type_fns_1.isAPromise)(result))
|
|
131
|
+
return result
|
|
132
|
+
.then((output) => {
|
|
133
|
+
logOutput(output);
|
|
134
|
+
return output;
|
|
135
|
+
})
|
|
136
|
+
.catch((error) => {
|
|
137
|
+
logError(error);
|
|
138
|
+
throw error;
|
|
139
|
+
});
|
|
140
|
+
// otherwise, its not a promise, so its done, so log now and return the result
|
|
141
|
+
logOutput(result);
|
|
142
|
+
return result;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
exports.withLogTrail = withLogTrail;
|
|
146
|
+
//# sourceMappingURL=withLogTrail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withLogTrail.js","sourceRoot":"","sources":["../../src/domain.operations/withLogTrail.ts"],"names":[],"mappings":";;;AAKA,mDAAyD;AACzD,uCAA4D;AAC5D,uCAAuD;AAQvD,MAAM,IAAI,GAAG,CAAC,GAAG,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC;AACtC,MAAM,WAAW,GAAG,CAAC,GAAG,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,+CAA+C;AAChG,MAAM,gBAAgB,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC;IAC1C,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;CAClC,CAAC,CAAC;AACH,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,+CAA+C;AAEvH,MAAM,iCAAiC,GAAG,OAAO,CAAC,GAAG;KAClD,6BAA6B;IAC9B,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;IACrD,CAAC,CAAC,IAAA,yBAAc,EAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;AAEnC;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAC1B,KAAoD,EACpD,EACE,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,U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AAC,CAAC;iBACD,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;gBACtB,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAChB,MAAM,KAAK,CAAC;YACd,CAAC,CAAY,CAAC;QAElB,8EAA8E;QAC9E,SAAS,CAAC,MAAgD,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC,CAAC;AA9NW,QAAA,YAAY,gBA8NvB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { LogLevel } from './domain.objects/constants';
|
|
2
|
+
export type { ContextLogTrail, HasContextLogTrail, LogTrail, } from './domain.objects/LogTrail';
|
|
3
|
+
export type { LogMethod } from './domain.operations/generateLogMethod';
|
|
4
|
+
export type { LogMethods } from './domain.operations/generateLogMethods';
|
|
5
|
+
export { generateLogMethods } from './domain.operations/generateLogMethods';
|
|
6
|
+
export { withLogTrail } from './domain.operations/withLogTrail';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withLogTrail = exports.generateLogMethods = exports.LogLevel = void 0;
|
|
4
|
+
var constants_1 = require("./domain.objects/constants");
|
|
5
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return constants_1.LogLevel; } });
|
|
6
|
+
var generateLogMethods_1 = require("./domain.operations/generateLogMethods");
|
|
7
|
+
Object.defineProperty(exports, "generateLogMethods", { enumerable: true, get: function () { return generateLogMethods_1.generateLogMethods; } });
|
|
8
|
+
var withLogTrail_1 = require("./domain.operations/withLogTrail");
|
|
9
|
+
Object.defineProperty(exports, "withLogTrail", { enumerable: true, get: function () { return withLogTrail_1.withLogTrail; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAAsD;AAA7C,qGAAA,QAAQ,OAAA;AAQjB,6EAA4E;AAAnE,wHAAA,kBAAkB,OAAA;AAC3B,iEAAgE;AAAvD,4GAAA,YAAY,OAAA"}
|
package/license.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 ehmpathy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sdk-logs",
|
|
3
|
+
"author": "ehmpathy",
|
|
4
|
+
"description": "a simple and opinionated logging library. plays well with aws lambda + cloudwatch.",
|
|
5
|
+
"version": "0.6.12",
|
|
6
|
+
"repository": "ehmpathy/sdk-logs",
|
|
7
|
+
"homepage": "https://github.com/ehmpathy/sdk-logs",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"log",
|
|
10
|
+
"logs",
|
|
11
|
+
"level",
|
|
12
|
+
"simple",
|
|
13
|
+
"filter",
|
|
14
|
+
"aws",
|
|
15
|
+
"lambda",
|
|
16
|
+
"cloudwatch",
|
|
17
|
+
"requestId"
|
|
18
|
+
],
|
|
19
|
+
"bugs": "https://github.com/ehmpathy/sdk-logs/issues",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=8.0.0"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"/dist"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@ehmpathy/error-fns": "^1.3.7",
|
|
30
|
+
"domain-glossary-procedure": "^1.0.0",
|
|
31
|
+
"domain-objects": "0.31.10",
|
|
32
|
+
"helpful-errors": "1.7.3",
|
|
33
|
+
"iso-time": "^1.11.5",
|
|
34
|
+
"type-fns": "1.21.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@biomejs/biome": "2.3.8",
|
|
38
|
+
"@commitlint/cli": "19.5.0",
|
|
39
|
+
"@commitlint/config-conventional": "19.5.0",
|
|
40
|
+
"@swc/core": "1.15.3",
|
|
41
|
+
"@swc/jest": "0.2.39",
|
|
42
|
+
"@tsconfig/node20": "20.1.5",
|
|
43
|
+
"@tsconfig/strictest": "2.0.5",
|
|
44
|
+
"@types/jest": "30.0.0",
|
|
45
|
+
"@types/node": "22.15.21",
|
|
46
|
+
"cz-conventional-changelog": "3.3.0",
|
|
47
|
+
"declapract": "^0.13.18",
|
|
48
|
+
"declapract-typescript-ehmpathy": "^0.47.14",
|
|
49
|
+
"declastruct": "1.7.3",
|
|
50
|
+
"declastruct-github": "1.3.0",
|
|
51
|
+
"depcheck": "1.4.3",
|
|
52
|
+
"esbuild-register": "3.6.0",
|
|
53
|
+
"husky": "8.0.3",
|
|
54
|
+
"jest": "30.2.0",
|
|
55
|
+
"rhachet": "1.41.4",
|
|
56
|
+
"rhachet-brains-anthropic": "^0.4.1",
|
|
57
|
+
"rhachet-brains-xai": "^0.3.3",
|
|
58
|
+
"rhachet-roles-bhrain": "0.27.6",
|
|
59
|
+
"rhachet-roles-bhuild": "0.21.4",
|
|
60
|
+
"rhachet-roles-ehmpathy": "1.35.0",
|
|
61
|
+
"rhachet-roles-rhachet": "^0.1.7",
|
|
62
|
+
"test-fns": "1.4.2",
|
|
63
|
+
"tsc-alias": "1.8.10",
|
|
64
|
+
"tsx": "4.20.6",
|
|
65
|
+
"typescript": "5.4.5",
|
|
66
|
+
"yalc": "1.0.0-pre.53"
|
|
67
|
+
},
|
|
68
|
+
"config": {
|
|
69
|
+
"commitizen": {
|
|
70
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build:ts": "tsc -p ./tsconfig.build.json",
|
|
75
|
+
"commit:with-cli": "npx cz",
|
|
76
|
+
"fix:format:biome": "biome check --write",
|
|
77
|
+
"fix:format": "npm run fix:format:biome",
|
|
78
|
+
"fix:lint": "biome check --write",
|
|
79
|
+
"fix": "npm run fix:format && npm run fix:lint",
|
|
80
|
+
"build:clean": "chmod -R u+w dist 2>/dev/null; rm -rf dist/",
|
|
81
|
+
"build:compile": "tsc -p ./tsconfig.build.json && tsc-alias -p ./tsconfig.build.json",
|
|
82
|
+
"build": "npm run build:clean && npm run build:compile && npm run build:complete --if-present",
|
|
83
|
+
"test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
|
|
84
|
+
"test:types": "tsc -p ./tsconfig.json --noEmit",
|
|
85
|
+
"test:format:biome": "biome format",
|
|
86
|
+
"test:format": "npm run test:format:biome",
|
|
87
|
+
"test:lint:deps": "npx depcheck -c ./.depcheckrc.yml",
|
|
88
|
+
"test:lint:biome": "biome check --diagnostic-level=error",
|
|
89
|
+
"test:lint:biome:all": "biome check",
|
|
90
|
+
"test:lint": "npm run test:lint:biome && npm run test:lint:deps",
|
|
91
|
+
"test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
|
|
92
|
+
"test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
|
|
93
|
+
"test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
|
|
94
|
+
"test": "npm run test:commits && npm run test:types && npm run test:format && npm run test:lint && npm run test:unit && npm run test:integration && npm run test:acceptance:locally",
|
|
95
|
+
"test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
|
|
96
|
+
"prepush": "npm run test && npm run build",
|
|
97
|
+
"prepublish": "npm run build",
|
|
98
|
+
"preversion": "npm run prepush",
|
|
99
|
+
"postversion": "git push origin HEAD --tags --no-verify",
|
|
100
|
+
"prepare:husky": "husky install && chmod ug+x .husky/*",
|
|
101
|
+
"prepare:rhachet": "rhachet init --hooks --roles mechanic behaver driver reviewer librarian ergonomist architect reflector dreamer dispatcher"
|
|
102
|
+
}
|
|
103
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# sdk-logs
|
|
2
|
+
|
|
3
|
+
a simple and opinionated logging library. plays well with aws lambda + cloudwatch.
|
|
4
|
+
|
|
5
|
+
# features
|
|
6
|
+
|
|
7
|
+
- distinguish different priorities of logs with standard levels
|
|
8
|
+
- i.e., `log.debug`, `log.info`, `log.warn`, and `log.error`
|
|
9
|
+
- filter which levels of log to emit
|
|
10
|
+
- i.e., choose based on environment whether to emit all logs or skip some of the logs
|
|
11
|
+
- utilizes `console.warn` and `console.log` under the hood
|
|
12
|
+
- which ensures that the aws cloudwatch requestId is present on each log message automatically
|
|
13
|
+
- formats log metadata based on environment
|
|
14
|
+
- i.e., stringify in local environments to reduce visual noise
|
|
15
|
+
- i.e., don't stringify in aws-lambda environment for optimal cloudwatch parsing
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# installation
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm install --save sdk-logs
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
# usage
|
|
25
|
+
|
|
26
|
+
### init
|
|
27
|
+
```ts
|
|
28
|
+
// e.g., in `src/utils/log.ts
|
|
29
|
+
import { generateLogMethods } from 'sdk-logs';
|
|
30
|
+
|
|
31
|
+
export const log = generateLogMethods();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### use in code
|
|
35
|
+
```ts
|
|
36
|
+
import { log } from '../utils/log';
|
|
37
|
+
|
|
38
|
+
log.error(`the sky is falling and we're loosing money!`, metadata); // use `.error` when you want someone to respond immediately, even if its 4am
|
|
39
|
+
|
|
40
|
+
log.warn(`this shouldn't be happening and should be looked at asap`, metadata); // use `.warn` when you want someone to look at it asap, but not wake up in the middle of the night
|
|
41
|
+
|
|
42
|
+
log.info(`we either want to or should keep track of this`, metadata); // use `.info` for anything we may be interested in knowing about
|
|
43
|
+
|
|
44
|
+
log.debug(`this will help debug if things go wrong`, metadata); // use this for any information that could help debug when things go wrong (e.g., request/response data)
|
|
45
|
+
```
|