Skip to main content

python-cloud-logger

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.

Usage

from pythoncloudlogger import *

logger=logging.getLogger("myapp-logger")

logger.updateContext({
  "requestId" : "1245"
})

logger.info("Request successfully processed")

logger.clearContext()

RedactJsonFormatter

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

Usage

# Set the environment variables
#
import logging,os

from pythonjsonlogger.formatters import RedactJsonFormatter

os.environ["redactionKeys"]="x-api-key,Authorization"
os.environ["redactionString"]="<secret>"

logger = logging.getLogger(__name__)

ch = logging.StreamHandler()
ch.setLevel(logging.INFO)

# create formatter and add it to the handlers
formatter = pythoncloudlogger.RedactJsonFormatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

logger.info({
	"message" : "My request details",
	"headers" : {
		# will be masked
		"x-api-key" : "sdfsf",
		"another-level" :{
			# will be masked
			"Authorization" : "Bearer dfsfd"
		}
	}

})

Release files for python-cloud-logger 0.1.1

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

Source distribution (sdist)

Source distribution for python-cloud-logger 0.1.1
File Size Uploaded
python-cloud-logger-0.1.1.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-cloud-logger 0.1.1
File Interpreter ABI Platform
python_cloud_logger-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / python-cloud-logger-0.1.1.tar.gz

Download URL python-cloud-logger-0.1.1.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
66935895a0661b9824042cb689ef96ce97e1aba70b2ee51105ac5b32c1ac2fc0
BLAKE2b-256 checksum
How to use checksums
0d708ba428a4a815a29ca7ba1dd03b07ead1b10a6479ec2854b9f299448e01ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / python_cloud_logger-0.1.1-py3-none-any.whl

Download URL python_cloud_logger-0.1.1-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84b1691c2f2550fccae7c3aebab657868876d7dc87cec4302911eab2166efcaf
BLAKE2b-256 checksum
How to use checksums
569e03e80b0339c56c362288959ebb439a6fb77d0c8e99915338b2c4e2ef9c7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

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