Skip to main content

Pielog

In long-running tools that center around calculating a result, one needs a way to see what the code has done before, and what is it doing right now. The former is logging; the latter is execution tracing.

Pielog is a minimal logging & execution tracing library for C++, Python, and Cython. It allows for seamless logging & tracing from a mixture of Python and C++ sources, threads, and subprocesses.

How to use

In Python:

import pielog as pl

with pl.trace("task"):
    for i in range(10):
        pl.log(f"working on item {i}")
        pl.trace_progress(i+1, 10)

In C++:

#include <pielog.h>

...

{
    trace_scope("task");
    for (int i = 0; i < 10; i++) {
        pr("working on item {}", i);
        trace_progress(i+1, 10);
    }
}

Note that the formatted printing here is its own facility, available standalone via #include <bprint.h>. We need it because the built-in C printing (printf) is not extensible, and the built-in C++ printing (iostream) is not convenient.

If you want your custom type to work in pr(), define this function:

static inline void
bprint(Buf &b, const your_type &x)
{
    b.print("my_type({}, {}, {})", 1, 2, "etc");
}

C++ API

pr(format, ...)

Print a log message.

trace_scope(format, ...)

Start a span (a traced region) with the given name, and automatically exit it at the end of the current lexical scope.

trace_enter(format, ...)

Enter a span with the given name.

trace_exit()

Exit the current span.

log_trace_scope(format, ...)

Start a span with the given name, log it, and automatically exit it at the end of the current lexical scope.

log_trace_enter(format, ...)

Enter a span with the given name, and log it.

log_trace_exit()

Exit the current span, and log it.

trace_text(format, ...)

Change the text of the current span.

trace_progress(ndone, ntotal)

Change the progress bar of the current span.

trace_here() → span

Get a reference to the current span that can be passed down to trace_scope_under.

trace_scope_under(span)

Set the given span to be the current, but automatically undo that at the end of the current lexical scope.

pielog_start_terminal()

Start a terminal renderer of the trace, unless a different one is already started by a parent process. This renderer will work as a separate thread, updating the display from time to time.

pielog_stop_terminal()

Stop the terminal renderer, if it was started by us.

Python API

Functions

auto_log_trace (fn: Callable[..., _T]) → Callable[..., _T]

Decorator: wrap each call of fn in a span named after it, logging entry and exit.

auto_trace (fn: Callable[..., _T]) → Callable[..., _T]

Decorator: wrap each call of fn in a span named after it.

here () → SpanRef

Return this context's current span, for use with trace_under()/wrap().

log (text: str)

Print one log line, indented one level under the nearest enclosing log_trace() (a trace() adds no indent).

log_trace (text: str) → AbstractContextManager[None]

Context manager: open a span around the body, logging entry and exit.

log_trace_enter (text: str)

Open a span around the code that follows, and log its opening.

log_trace_exit ()

Close the span opened by log_trace_enter(), and log its completion.

start_terminal ()

Start a terminal renderer of the trace, unless a different one is already started by a parent process.

stop_terminal ()

Stop the terminal renderer, if it was started by us.

trace (text: str) → AbstractContextManager[None]

Context manager: open a span around the body.

trace_enter (text: str)

Open a span around the code that follows.

trace_exit ()

Close the span opened by trace_enter().

trace_progress (items_done: int | float, items_total: int | float)

Report progress of the current span.

trace_text (text: str)

Rename the current span.

trace_under (parent: SpanRef) → AbstractContextManager[None]

Context manager: log the body under the given span, opening no span of its own -- scopes started inside hang under it. The body must be balanced: a trace_exit() closes the target span, and trace_text()/trace_progress() act on it.

wrap (fn: Callable[..., _T], span: SpanRef | None) → Callable[..., _T]

Return fn wrapped to run under the given span (or current one).

Classes

class SpanRef

Metadata

Release files for pielog 0.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 pielog 0.1
File Size Uploaded Provenance Actions
pielog-0.1.tar.gz 29.1 kB Without provenance Details for pielog-0.1.tar.gz

Release files / pielog-0.1.tar.gz

Download URL pielog-0.1.tar.gz
Size 29.1 kB
Tags Source
SHA-256 checksum
How to use checksums
66f687638a7fcd4e56d8a0a65fae8a73e28f3d5de9033e7f6bca860678f8ca21
BLAKE2b-256 checksum
How to use checksums
7e17cb000c4b013a9f4c204555859e9d06a19a66aede4598ef1704abae79fa51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Security for pielog 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

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