@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 CHANGED
@@ -1 +1 @@
1
- export { initializeLogger, logger, LoggerConfig } from './logging/logger';
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 { StructuredLogFormatter, pinoLambdaDestination, CloudwatchLogFormatter } from 'pino-lambda';
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
- * Pino logger instance
70
- * Configuration is supplied via initializeLogger() and persists across imports
71
- * Logger instance is cached after first creation for reuse
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 logger = _getLogger();
83
+ const getLogger = () => {
84
+ if (_loggerInstance === null) {
85
+ _loggerInstance = _createLogger();
86
+ }
87
+ return _loggerInstance;
88
+ };
74
89
 
75
- export { initializeLogger, logger };
90
+ export { getLogger, initializeLogger, withRequestTracking };
@@ -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
- * Pino logger instance
35
- * Configuration is supplied via initializeLogger() and persists across imports
36
- * Logger instance is cached after first creation for reuse
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 logger: pino.Logger<never, boolean>;
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.1",
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 { initializeLogger, logger, LoggerConfig } from './logging/logger';
1
+ export { getLogger, initializeLogger, LoggerConfig, withRequestTracking } from './logging/logger';
@@ -1,5 +1,25 @@
1
1
  import pino from 'pino';
2
- import { CloudwatchLogFormatter, pinoLambdaDestination, StructuredLogFormatter } from 'pino-lambda';
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
- * Pino logger instance
92
- * Configuration is supplied via initializeLogger() and persists across imports
93
- * Logger instance is cached after first creation for reuse
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 logger = _getLogger();
110
+ export const getLogger = (): pino.Logger => {
111
+ if (_loggerInstance === null) {
112
+ _loggerInstance = _createLogger();
113
+ }
114
+ return _loggerInstance;
115
+ };