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
File details
Details for the file aws_lambda_logger_for_python-0.1.1.tar.gz
.
File metadata
- Download URL: aws_lambda_logger_for_python-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2af47c0b7fbe3145c9620cd7cc77101f7febc6fc146cc0f53039218a78132189 |
|
MD5 | 301c8e2744e6e97dcbd6b4170f28104f |
|
BLAKE2b-256 | a8935089883f3de2d6f8f7d5844b87eff881cac3c652210e38a304c960cf2b2e |