Do natural python logging in a natural manner
Project description
goodlog
Built on top the standard library's logging, this package allows for quick and simple logging configuration and provides useful, common utilities like JSON formatting and adding extra info to logs, with minimal configuration.
Install
pip install goodlog
Quick start
import goodlog
# Configure logging once at application startup
goodlog.configure_logging(global_extra_info={"service": "my-app"})
# Create a logger and use it
logger = goodlog.create_logger(__name__)
logger.info("Application started")
Logs are emitted as JSON to stdout:
{"logger_name": "__main__", "timestamp": "2025-01-01 12:00:00,000", "log_level": "INFO", "message": "Application started", "extra_info": {"service": "my-app"}, ...}
Adding ephemeral extra info
Use the ephemeral_info_context context manager to attach extra fields to all logs within a scope:
from goodlog import ephemeral_info_context, create_logger
logger = create_logger(__name__)
with ephemeral_info_context(user_id=42):
logger.info("Some user action")
logger.info("Some later action")
Output log will be:
{"logger_name": "__main__", "timestamp": "2025-01-01 12:00:00,000", "log_level": "INFO", "message": "Some user action", "extra_info": {"service": "my-app", "user_id": 42}, ...}
{"logger_name": "__main__", "timestamp": "2025-01-01 12:00:00,000", "log_level": "INFO", "message": "Some later action", "extra_info": {"service": "my-app"}, ...}
Inside the context, use add to add more info along the way:
from goodlog import ephemeral_info_context, create_logger, add
logger = create_logger(__name__)
with ephemeral_info_context(user_id=42):
logger.info("Some user action")
... # some logic discovering the user name
add(user_name="John Doe")
logger.info("Discovered user name")
logger.info("Some later action")
Output log will be:
{... "message": "Some user action", "extra_info": {"service": "my-app", "user_id": 42}, ...}
{... "message": "Discovered user name", "extra_info": {"service": "my-app", "user_id": 42, "user_name": "John Doe"}, ...}
{... "message": "Some later action", "extra_info": {"service": "my-app"}, ...}
The remove function can be used to remove ephemeral info to add more info along the way:
from goodlog import ephemeral_info_context, create_logger, add, remove
logger = create_logger(__name__)
with ephemeral_info_context(user_id=42):
logger.info("Some user action")
... # some logic discovering the user name
add(user_name="John Doe")
logger.info("Discovered user name")
remove()
logger.info("No extra info here")
Output log will be:
{... "message": "Some user action", "extra_info": {"service": "my-app", "user_id": 42}, ...}
{... "message": "Discovered user name", "extra_info": {"service": "my-app", "user_id": 42, "user_name": "John Doe"}, ...}
{... "message": "No extra info here", "extra_info": {"service": "my-app"}, ...}
As you can see, calling remove explicitly inside the context has the same effect as if we are already out of the context's scope.
Links
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file goodlog-0.0.1rc6.tar.gz.
File metadata
- Download URL: goodlog-0.0.1rc6.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
216bd5bbbeda77dee8e7234cb3d8c91705d19c39ad6488325c7c9df413432c90
|
|
| MD5 |
5245b604379628b23dd21ef684b5b21a
|
|
| BLAKE2b-256 |
636da6fdb16fe5c53a1ac2746bb51244b35b984704c43f9b7ef12134b7165ba5
|
Provenance
The following attestation bundles were made for goodlog-0.0.1rc6.tar.gz:
Publisher:
publish.yml on benronen8/goodlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
goodlog-0.0.1rc6.tar.gz -
Subject digest:
216bd5bbbeda77dee8e7234cb3d8c91705d19c39ad6488325c7c9df413432c90 - Sigstore transparency entry: 776225683
- Sigstore integration time:
-
Permalink:
benronen8/goodlog@92764f40fa6bde5e9bff434dde793e6e66f55c2b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/benronen8
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@92764f40fa6bde5e9bff434dde793e6e66f55c2b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file goodlog-0.0.1rc6-py3-none-any.whl.
File metadata
- Download URL: goodlog-0.0.1rc6-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d342b78f26c72a9ccebb5f6a5a46b82dfb3580ecaf2867fdaab15bfa2b63a6e5
|
|
| MD5 |
59d8698dc9489a97ba6e4787b8c60497
|
|
| BLAKE2b-256 |
46319969029646e9ba090cddcfaadb1b321ad4a11676068bd980497558776ada
|
Provenance
The following attestation bundles were made for goodlog-0.0.1rc6-py3-none-any.whl:
Publisher:
publish.yml on benronen8/goodlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
goodlog-0.0.1rc6-py3-none-any.whl -
Subject digest:
d342b78f26c72a9ccebb5f6a5a46b82dfb3580ecaf2867fdaab15bfa2b63a6e5 - Sigstore transparency entry: 776225684
- Sigstore integration time:
-
Permalink:
benronen8/goodlog@92764f40fa6bde5e9bff434dde793e6e66f55c2b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/benronen8
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@92764f40fa6bde5e9bff434dde793e6e66f55c2b -
Trigger Event:
workflow_dispatch
-
Statement type: