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.
Metadata
Release files for aws-lambda-logging 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aws_lambda_logging-0.1.1.tar.gz | 3.8 kB | Without provenance | Details |
Release files / aws_lambda_logging-0.1.1.tar.gz
| Download URL | aws_lambda_logging-0.1.1.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c192bcdaf76e9bae61759efe98dc6b513746762a216161f689bf3ad73fe09d06
|
|
BLAKE2b-256 checksum How to use checksums |
940e8357fd958d48004fc0a2813c22538adbeab2607f56d74dfff8a16d433a2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for aws-lambda-logging 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.