Skip to main content

A logger with thread local storage for logging context in all logs without repeating the code

Project description


A logger with thread local storage for logging context in all logs without repeating the code. This is a json logger where some contextual fields need to be included in every log per request/thread in a safe and efficient way.

Note that, all the loggers retrieved on that particular thread ( by using logging.getLogger ) will inherit the context.


from pythoncloudlogger import *


  "requestId" : "1245"
})"Request successfully processed")



This formatter is an extension of pythonjsonlogger ( ). This extension will allow you to mask fields in the json before it logs. The redaction keys are case insensitive.


# Set the environment variables
import logging,os

from pythonjsonlogger.formatters import RedactJsonFormatter


logger = logging.getLogger(__name__)

ch = logging.StreamHandler()

# create formatter and add it to the handlers
formatter = pythoncloudlogger.RedactJsonFormatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
	"message" : "My request details",
	"headers" : {
		# will be masked
		"x-api-key" : "sdfsf",
		"another-level" :{
			# will be masked
			"Authorization" : "Bearer dfsfd"


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-cloud-logger-0.1.1.tar.gz (3.0 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page