@leanstacks/lambda-utils 0.1.0-alpha.2 → 0.1.0-alpha.4
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/.github/ISSUE_TEMPLATE/bug.md +47 -0
- package/.github/ISSUE_TEMPLATE/story.md +25 -0
- package/.github/ISSUE_TEMPLATE/task.md +15 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +39 -0
- package/README.md +178 -1
- package/docs/LOGGING.md +333 -0
- package/docs/README.md +14 -35
- package/jest.config.ts +4 -4
- package/package.json +8 -9
- package/src/index.ts +1 -1
- package/src/logging/logger.test.ts +400 -0
- package/src/logging/logger.ts +62 -73
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -90
- package/dist/logging/logger.d.ts +0 -57
package/dist/index.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import pino from 'pino';
|
|
2
|
-
import { lambdaRequestTracker, StructuredLogFormatter, CloudwatchLogFormatter, pinoLambdaDestination } from 'pino-lambda';
|
|
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();
|
|
18
|
-
/**
|
|
19
|
-
* Module-level state to store logger configuration
|
|
20
|
-
*/
|
|
21
|
-
let _loggerConfig = {
|
|
22
|
-
enabled: true,
|
|
23
|
-
level: 'info',
|
|
24
|
-
format: 'json',
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Module-level cache for the logger instance
|
|
28
|
-
*/
|
|
29
|
-
let _loggerInstance = null;
|
|
30
|
-
/**
|
|
31
|
-
* Create and return the Pino Lambda logger instance
|
|
32
|
-
* Uses the configuration set by initializeLogger
|
|
33
|
-
* Logger instance is cached after first creation
|
|
34
|
-
*/
|
|
35
|
-
const _createLogger = () => {
|
|
36
|
-
const formatter = _loggerConfig.format === 'json' ? new StructuredLogFormatter() : new CloudwatchLogFormatter();
|
|
37
|
-
const lambdaDestination = pinoLambdaDestination({
|
|
38
|
-
formatter,
|
|
39
|
-
});
|
|
40
|
-
return pino({
|
|
41
|
-
enabled: _loggerConfig.enabled,
|
|
42
|
-
level: _loggerConfig.level,
|
|
43
|
-
}, lambdaDestination);
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Initialize the logger with configuration
|
|
47
|
-
* Should be called once at Lambda handler entry point
|
|
48
|
-
* Invalidates the cached logger instance so a new one is created with the updated config
|
|
49
|
-
*
|
|
50
|
-
* @param config Logger configuration options
|
|
51
|
-
* @returns void
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* import { initializeLogger } from '@utils/logging/logger';
|
|
56
|
-
*
|
|
57
|
-
* initializeLogger({
|
|
58
|
-
* enabled: true,
|
|
59
|
-
* level: 'debug',
|
|
60
|
-
* format: 'json',
|
|
61
|
-
* });
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
const initializeLogger = (config) => {
|
|
65
|
-
_loggerConfig = {
|
|
66
|
-
enabled: config.enabled ?? true,
|
|
67
|
-
level: config.level ?? 'info',
|
|
68
|
-
format: config.format ?? 'json',
|
|
69
|
-
};
|
|
70
|
-
// Invalidate the cached logger instance so a new one is created with updated config
|
|
71
|
-
_loggerInstance = null;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Get the logger instance
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```typescript
|
|
78
|
-
* import { logger } from '@utils/logging/logger';
|
|
79
|
-
*
|
|
80
|
-
* logger.info('Hello, world!');
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
const getLogger = () => {
|
|
84
|
-
if (_loggerInstance === null) {
|
|
85
|
-
_loggerInstance = _createLogger();
|
|
86
|
-
}
|
|
87
|
-
return _loggerInstance;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export { getLogger, initializeLogger, withRequestTracking };
|
package/dist/logging/logger.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
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;
|
|
16
|
-
/**
|
|
17
|
-
* Configuration options for the Pino Lambda logger
|
|
18
|
-
*/
|
|
19
|
-
export interface LoggerConfig {
|
|
20
|
-
/** Whether logging is enabled */
|
|
21
|
-
enabled?: boolean;
|
|
22
|
-
/** Minimum log level (e.g., 'debug', 'info', 'warn', 'error') */
|
|
23
|
-
level?: 'debug' | 'info' | 'warn' | 'error';
|
|
24
|
-
/** Output format: 'json' for StructuredLogFormatter, 'text' for CloudwatchLogFormatter */
|
|
25
|
-
format?: 'json' | 'text';
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Initialize the logger with configuration
|
|
29
|
-
* Should be called once at Lambda handler entry point
|
|
30
|
-
* Invalidates the cached logger instance so a new one is created with the updated config
|
|
31
|
-
*
|
|
32
|
-
* @param config Logger configuration options
|
|
33
|
-
* @returns void
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* import { initializeLogger } from '@utils/logging/logger';
|
|
38
|
-
*
|
|
39
|
-
* initializeLogger({
|
|
40
|
-
* enabled: true,
|
|
41
|
-
* level: 'debug',
|
|
42
|
-
* format: 'json',
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare const initializeLogger: (config: LoggerConfig) => void;
|
|
47
|
-
/**
|
|
48
|
-
* Get the logger instance
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* import { logger } from '@utils/logging/logger';
|
|
53
|
-
*
|
|
54
|
-
* logger.info('Hello, world!');
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export declare const getLogger: () => pino.Logger;
|