@leanstacks/lambda-utils 0.1.0-alpha.1 → 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -15
- package/dist/logging/logger.d.ts +23 -4
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/logging/logger.ts +35 -15
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getLogger, initializeLogger, LoggerConfig, withRequestTracking } from './logging/logger';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import pino from 'pino';
|
|
2
|
-
import {
|
|
2
|
+
import { lambdaRequestTracker, StructuredLogFormatter, CloudwatchLogFormatter, pinoLambdaDestination } from 'pino-lambda';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Middleware to track AWS Lambda requests
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { withRequestTracking } from '@utils/logging/logger';
|
|
9
|
+
*
|
|
10
|
+
* export const handler = async (event, context) => {
|
|
11
|
+
* withRequestTracking(event, context);
|
|
12
|
+
*
|
|
13
|
+
* // Your Lambda handler logic here
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
const withRequestTracking = lambdaRequestTracker();
|
|
4
18
|
/**
|
|
5
19
|
* Module-level state to store logger configuration
|
|
6
20
|
*/
|
|
@@ -28,15 +42,6 @@ const _createLogger = () => {
|
|
|
28
42
|
level: _loggerConfig.level,
|
|
29
43
|
}, lambdaDestination);
|
|
30
44
|
};
|
|
31
|
-
/**
|
|
32
|
-
* Get the cached logger instance, creating it if necessary
|
|
33
|
-
*/
|
|
34
|
-
const _getLogger = () => {
|
|
35
|
-
if (_loggerInstance === null) {
|
|
36
|
-
_loggerInstance = _createLogger();
|
|
37
|
-
}
|
|
38
|
-
return _loggerInstance;
|
|
39
|
-
};
|
|
40
45
|
/**
|
|
41
46
|
* Initialize the logger with configuration
|
|
42
47
|
* Should be called once at Lambda handler entry point
|
|
@@ -66,10 +71,20 @@ const initializeLogger = (config) => {
|
|
|
66
71
|
_loggerInstance = null;
|
|
67
72
|
};
|
|
68
73
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
74
|
+
* Get the logger instance
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* import { logger } from '@utils/logging/logger';
|
|
79
|
+
*
|
|
80
|
+
* logger.info('Hello, world!');
|
|
81
|
+
* ```
|
|
72
82
|
*/
|
|
73
|
-
const
|
|
83
|
+
const getLogger = () => {
|
|
84
|
+
if (_loggerInstance === null) {
|
|
85
|
+
_loggerInstance = _createLogger();
|
|
86
|
+
}
|
|
87
|
+
return _loggerInstance;
|
|
88
|
+
};
|
|
74
89
|
|
|
75
|
-
export { initializeLogger,
|
|
90
|
+
export { getLogger, initializeLogger, withRequestTracking };
|
package/dist/logging/logger.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import pino from 'pino';
|
|
2
|
+
/**
|
|
3
|
+
* Middleware to track AWS Lambda requests
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { withRequestTracking } from '@utils/logging/logger';
|
|
7
|
+
*
|
|
8
|
+
* export const handler = async (event, context) => {
|
|
9
|
+
* withRequestTracking(event, context);
|
|
10
|
+
*
|
|
11
|
+
* // Your Lambda handler logic here
|
|
12
|
+
* };
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const withRequestTracking: (event: import("pino-lambda").LambdaEvent, context: import("pino-lambda").LambdaContext) => void;
|
|
2
16
|
/**
|
|
3
17
|
* Configuration options for the Pino Lambda logger
|
|
4
18
|
*/
|
|
@@ -31,8 +45,13 @@ export interface LoggerConfig {
|
|
|
31
45
|
*/
|
|
32
46
|
export declare const initializeLogger: (config: LoggerConfig) => void;
|
|
33
47
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
48
|
+
* Get the logger instance
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { logger } from '@utils/logging/logger';
|
|
53
|
+
*
|
|
54
|
+
* logger.info('Hello, world!');
|
|
55
|
+
* ```
|
|
37
56
|
*/
|
|
38
|
-
export declare const
|
|
57
|
+
export declare const getLogger: () => pino.Logger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leanstacks/lambda-utils",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"description": "A collection of utilities and helper functions designed to streamline the development of AWS Lambda functions using TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getLogger, initializeLogger, LoggerConfig, withRequestTracking } from './logging/logger';
|
package/src/logging/logger.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import pino from 'pino';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CloudwatchLogFormatter,
|
|
4
|
+
lambdaRequestTracker,
|
|
5
|
+
pinoLambdaDestination,
|
|
6
|
+
StructuredLogFormatter,
|
|
7
|
+
} from 'pino-lambda';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Middleware to track AWS Lambda requests
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { withRequestTracking } from '@utils/logging/logger';
|
|
14
|
+
*
|
|
15
|
+
* export const handler = async (event, context) => {
|
|
16
|
+
* withRequestTracking(event, context);
|
|
17
|
+
*
|
|
18
|
+
* // Your Lambda handler logic here
|
|
19
|
+
* };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const withRequestTracking = lambdaRequestTracker();
|
|
3
23
|
|
|
4
24
|
/**
|
|
5
25
|
* Configuration options for the Pino Lambda logger
|
|
@@ -48,16 +68,6 @@ const _createLogger = (): pino.Logger => {
|
|
|
48
68
|
);
|
|
49
69
|
};
|
|
50
70
|
|
|
51
|
-
/**
|
|
52
|
-
* Get the cached logger instance, creating it if necessary
|
|
53
|
-
*/
|
|
54
|
-
const _getLogger = (): pino.Logger => {
|
|
55
|
-
if (_loggerInstance === null) {
|
|
56
|
-
_loggerInstance = _createLogger();
|
|
57
|
-
}
|
|
58
|
-
return _loggerInstance;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
71
|
/**
|
|
62
72
|
* Initialize the logger with configuration
|
|
63
73
|
* Should be called once at Lambda handler entry point
|
|
@@ -88,8 +98,18 @@ export const initializeLogger = (config: LoggerConfig): void => {
|
|
|
88
98
|
};
|
|
89
99
|
|
|
90
100
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
101
|
+
* Get the logger instance
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { logger } from '@utils/logging/logger';
|
|
106
|
+
*
|
|
107
|
+
* logger.info('Hello, world!');
|
|
108
|
+
* ```
|
|
94
109
|
*/
|
|
95
|
-
export const
|
|
110
|
+
export const getLogger = (): pino.Logger => {
|
|
111
|
+
if (_loggerInstance === null) {
|
|
112
|
+
_loggerInstance = _createLogger();
|
|
113
|
+
}
|
|
114
|
+
return _loggerInstance;
|
|
115
|
+
};
|