Simple contextual logger
Project description
simple_ctx_log
A lightweight but deeply introspective logger for Python.
simple_ctx_log focuses on context reconstruction, not just file/line logging.
It is designed to answer the question:
“From which object, through which call stack, did this log originate?”
No external dependencies. No global state. No magic decorators. Just frames, objects, and clarity.
Key Features
- 🔍 Full call stack reconstruction (functions and methods)
- 🧠 Object context traversal (parent objects, nested architectures)
- 🧵 Safe with recursion, deep nesting, and complex object graphs
- 🛑 Configurable limits:
- maximum depth
- stop at module boundary
- 📐 Highly readable tree-style output
- ⚡ High performance (uses
sys._getframe, noinspect.stack) - 🧪 Designed to be test-friendly
- 📦 Standard library only
This logger is particularly useful for:
- debugging complex object-oriented flows
- understanding “who called what” in large systems
- forensic-style debugging
- frameworks, factories, and deeply nested architectures
Table of Contents
Installation
pip install simple_ctx_log
Quick Start
from simple_ctx_log import Logger
logger = Logger()
def my_function(x):
logger.log("Hello from my_function")
my_function(42)
Example Output
For a deeply nested and recursive call:
[2026-01-xxThh:mm:ss.mls] [INFO] [thread=MainThread]
│ module: tests.test_logger_nested_hell
│ call stack:
│ ├─ ExternalArchitect.<unknown>
│ │ attrs:
│ │ creator = 'Hell'
│ │ data = 'Data'
│ ├─ test_logger_called_from_function(capsys=<_pytest.capture.CaptureFixture>)
│ ├─ InternProcess.recursive_log_call(depth=3, msg='Entropy is inevitable.')
│ │ attrs:
│ │ parent = <ExternalArchitect>
│ ├─ InternProcess.recursive_log_call(depth=2, msg='Entropy is inevitable.')
│ │ attrs:
│ │ parent = <ExternalArchitect>
│ ├─ InternProcess.recursive_log_call(depth=1, msg='Entropy is inevitable.')
│ │ attrs:
│ │ parent = <ExternalArchitect>
│ └─ InternProcess.recursive_log_call(depth=0, msg='Entropy is inevitable.')
│ attrs:
│ parent = <ExternalArchitect>
│
└─ message:
Retrieved message : Entropy is inevitable.
This output shows:
- the full call stack (module → logger call)
- recursive calls
- object hierarchy
- method arguments
- instance attributes
- a clean separation between context and message
Configuration
Logger options
Logger(
name: str | None = None,
log_args: bool = True,
log_attrs: bool = True,
log_private_attrs: bool = False,
max_depth: int | None = None,
log_file: str | None = None,
stdout: bool = True,
signing_key: bytes | None = None
)
| Option | Description |
|---|---|
name |
Logger name (informational) |
log_args |
Log function/method arguments |
log_attrs |
Log instance attributes |
log_private_attrs |
Include private attributes (_attr) |
max_depth |
Maximum depth for call stack + object traversal |
log_file |
optional file in which to write logs |
stdout |
Print logs |
signing_key |
Hash key |
Module boundary safety
The logger does not cross module boundaries by default. This prevents polluting logs with internals such as:
asynciothreading- framework internals
The context stops at the last object belonging to the calling module.
Design Philosophy
simple_ctx_log intentionally does not:
- wrap or replace
logging - rely on decorators
- inject global hooks
- inspect the heap (
gc) - traverse object graphs downward
Instead, it:
- walks upward through frames
- reconstructs logical ownership
- remains deterministic and bounded
The goal is understanding, not verbosity.
Limitations
- Uses
sys._getframe(CPython only) - Output is currently text-based (no JSON yet)
- No built-in log levels filtering (by design, for now)
- No file handler yet (planned)
These are deliberate trade-offs to preserve performances.
License
simple_ctx_log is distributed under the terms of the
MIT license.
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 simple_ctx_log-0.0.3.tar.gz.
File metadata
- Download URL: simple_ctx_log-0.0.3.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3b98170fd4852d0d7205196b6b42c9c34205360f4481017fcf234f161752b0d
|
|
| MD5 |
5ce324939a4ed7ca5e40c106a017cea9
|
|
| BLAKE2b-256 |
a27f05c05ae1d143e6cd35dd5ba5374f652415eb22be3072fb76ee5ecba8e62e
|
Provenance
The following attestation bundles were made for simple_ctx_log-0.0.3.tar.gz:
Publisher:
publish.yml on Hactys/simple-ctx-log
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simple_ctx_log-0.0.3.tar.gz -
Subject digest:
d3b98170fd4852d0d7205196b6b42c9c34205360f4481017fcf234f161752b0d - Sigstore transparency entry: 894688314
- Sigstore integration time:
-
Permalink:
Hactys/simple-ctx-log@e14d5966105da046090871e8f493e143678a631d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Hactys
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e14d5966105da046090871e8f493e143678a631d -
Trigger Event:
push
-
Statement type:
File details
Details for the file simple_ctx_log-0.0.3-py3-none-any.whl.
File metadata
- Download URL: simple_ctx_log-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.6 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 |
27187c9aad1ae618a4b1bfe2c83b54d8add4cdd4600a6b5d64b16f0a8294d462
|
|
| MD5 |
773b57afa504a893edebe154eae3e9e7
|
|
| BLAKE2b-256 |
0eb53849b738411d4fce954ea873c680559275dc0f3a6cfb7dcc3a17ff2d658b
|
Provenance
The following attestation bundles were made for simple_ctx_log-0.0.3-py3-none-any.whl:
Publisher:
publish.yml on Hactys/simple-ctx-log
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simple_ctx_log-0.0.3-py3-none-any.whl -
Subject digest:
27187c9aad1ae618a4b1bfe2c83b54d8add4cdd4600a6b5d64b16f0a8294d462 - Sigstore transparency entry: 894688316
- Sigstore integration time:
-
Permalink:
Hactys/simple-ctx-log@e14d5966105da046090871e8f493e143678a631d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Hactys
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e14d5966105da046090871e8f493e143678a631d -
Trigger Event:
push
-
Statement type: