Logging¶
Logging configuration and utilities for Lambda handlers.
Logging utilities for AWS Lambda handlers.
Provides logging mixins and helper functions for configuring structured logging with AWS Lambda Powertools.
LoggingMixins ¶
Bases: HandlerMixins
Mixin class providing structured logging capabilities.
Integrates AWS Lambda Powertools Logger for structured JSON logging with automatic context injection and correlation IDs.
Attributes:
| Name | Type | Description |
|---|---|---|
log |
Logger
|
Alias for the logger property. |
logger |
Logger
|
The AWS Lambda Powertools Logger instance. |
log
property
writable
¶
log
Alias for the logger property.
Returns:
| Type | Description |
|---|---|
Logger
|
The configured Logger instance. |
logger
property
writable
¶
logger
Get the Logger instance, creating one if needed.
Returns:
| Type | Description |
|---|---|
Logger
|
The configured Logger instance for this handler. |
add_logger_to_root ¶
add_logger_to_root()
Add this handler's logger to the root logger.
Ensures log messages from other modules are captured with the same structured format.
Source code in src/aibs_informatics_aws_lambda/common/logging.py
88 89 90 91 92 93 94 | |
get_logger
classmethod
¶
get_logger(service=None, add_to_root=False)
Create a new Logger instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
Optional[str]
|
The service name for the logger. If None, uses default. |
None
|
add_to_root
|
bool
|
Whether to add the logger handler to the root logger. |
False
|
Returns:
| Type | Description |
|---|---|
Logger
|
A configured Logger instance. |
Source code in src/aibs_informatics_aws_lambda/common/logging.py
75 76 77 78 79 80 81 82 83 84 85 86 | |
add_handler_to_logger ¶
add_handler_to_logger(source_logger, target_logger=None)
Add a source logger's handler to a target logger.
Copies the handler from the source logger to the target logger, ensuring consistent log formatting across loggers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_logger
|
Logger
|
The Logger whose handler will be copied. |
required |
target_logger
|
Union[str, Logger, None]
|
The target logger to receive the handler. Can be a logger name string, a Logger instance, or None for the root logger. |
None
|
Source code in src/aibs_informatics_aws_lambda/common/logging.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
get_service_logger ¶
get_service_logger(
service=None, child=False, add_to_root=False
)
Create a service logger with optional root logger integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
Optional[str]
|
The service name for the logger. If None, uses default. |
None
|
child
|
bool
|
Whether to create a child logger. |
False
|
add_to_root
|
bool
|
Whether to add the logger handler to the root logger. |
False
|
Returns:
| Type | Description |
|---|---|
Logger
|
A configured Logger instance for the service. |
Source code in src/aibs_informatics_aws_lambda/common/logging.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |