Skip to main content

json-logger

Import into your Python project to standardize logs to JSON format. Works well with AWS CloudWatch and AWS Lambda Functions.

Installation

pip install -U bazze-json-logger

Usage

This package sets up a JSON formatter for the Python root logger. In order for this to work properly, be sure to run this package before setting up any new loggers.

import logging

import bazze_json_logger

logging.basicConfig(level=logging.INFO)

bazze_json_logger.setup()

logger = logging.getLogger()
logger.info('Hello World!')

Output

>>> {"timestamp": "2020-09-30T00:15:39.667110Z", "level": "INFO", "name": "root", "message": "Hello World!", "schema_version": "0.0.2"}

AWS Lambda Integration

When using AWS Lambda it is nice to have the aws_request_id as part of the JSON object for tracing purposes. To do this we need to pass it into the setup() method.

import logging

import bazze_json_logger

logging.basicConfig(level=logging.INFO)


def lambda_handler(event, context):
    bazze_json_logger.setup(aws_request_id=context.aws_request_id)
    logger = logging.getLogger()
    logger.info('Hello World!')

Viewing the logs on AWS

Logs can be viewed locally in your terminal when testings. When the application is deployed, they will show up in the CloudWatch group in JSON format.

To view the CloudWatch logs in your console:

Install awslogs

pip install -U awslogs

Export AWS_PROFILE

export AWS_PROFILE=bazze

To view all log groups:

awslogs groups

To tail your log group:

awslogs get /aws/lambda/your-function --since 5m --watch

To query and aggregate the logs, I recommend using CloudWatch Insights.

Release files for bazze-json-logger 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bazze-json-logger 0.0.3
File Size Uploaded
bazze-json-logger-0.0.3.tar.gz 2.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bazze-json-logger 0.0.3
File Interpreter ABI Platform
bazze_json_logger-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 kB

Release files / bazze-json-logger-0.0.3.tar.gz

Download URL bazze-json-logger-0.0.3.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fba33a00b28ed330b292241a14143a9376c506d2d8bd99251ebc48c8252dab81
BLAKE2b-256 checksum
How to use checksums
51c1914453e5e1941ed30a464ece0eba0947830e9ac7c5c15ab6f2640edaadf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.9

Release files / bazze_json_logger-0.0.3-py3-none-any.whl

Download URL bazze_json_logger-0.0.3-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb36f8ab665b84c125c433a82d437535a8eb03bd086f9928fd039240058406d2
BLAKE2b-256 checksum
How to use checksums
d70f61211f4ab73e1d026449a5e36f22f107efac515525411b6ffb39e4588bb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.9

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page