Nanolib to enhance logging in aws lambda
Project description
Better logging for aws lambda running on python runtime environment with a highly opinionated JSON formatting to ease parsing on any logging system.
Usage
import aws_lambda_logging
def handler(event, context):
aws_lambda_logging.setup(level='DEBUG')
...
You can separately set the logging level for Boto (defaults to the same level):
import aws_lambda_logging
def handler(event, context):
aws_lambda_logging.setup(level='DEBUG', boto_level='CRITICAL')
...
You can add keyword arguments to be logged each time, such as lambda request id.
import aws_lambda_logging
def handler(event, context):
aws_lambda_logging.setup(level='DEBUG',
aws_request_id=context.get('aws_request_id'))
log.debug('Just a try!')
...
It will output JSON formatted message:
{
"level": "DEBUG",
"timestamp": "2016-10-03 13:27:57,438",
"apigw_request_id": "323fee86-896d-11e6-b7fd-2d914ea80962",
"location": "root.handler:6",
"message": "Just a try!"
}
You can input a JSON string:
log.debug('{"Details": [1,2,3]}')
It will output JSON formatted message with the JSON string embedded properly:
{
"level": "DEBUG",
"timestamp": "2016-10-03 13:27:57,438",
"apigw_request_id": "323fee86-896d-11e6-b7fd-2d914ea80962",
"location": "root.handler:6",
"message": {
"Details": [
1,
2,
3
]
}
}
You can input a dict:
log.debug({"Details": [1,2,3]})
It will output JSON formatted message with the dict values:
{
"level": "DEBUG",
"timestamp": "2016-10-03 13:27:57,438",
"apigw_request_id": "323fee86-896d-11e6-b7fd-2d914ea80962",
"location": "root.handler:6",
"message": {
"Details": [
1,
2,
3
]
}
}
Any values that can otherwise be serialisabled to JSON are coerced to strings. This behaviour can be changed by parsing a formatter function to the json_default keyword argument.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for aws_lambda_logging-0.0.23.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba1d116d934513e71704cd877b39a77c95df7447d1f8596d0ae8643bb42d7034 |
|
MD5 | 9561391d9147035efc903adee32be45c |
|
BLAKE2b-256 | 19a75c9b1e4d36980966cab794dde8966d45fabbd1f334f0a05948afee2ab4df |