Skip to main content

SMFLOG

smflog is a high-performance logging library for Python rewritten using Rust and PyO3. Serves as a drop-in extension for print() Python defaults, smflog offers much lower overhead, massive log throughput handling, and separation of log execution between output terminals and persistent SQLite storage.


Key Features & Architecture

Zero-Lag Terminal I/O (smf.printf): Replaces Python's built-in I/O mechanism with Rust FFI bindings optimized for executing large logs without triggering I/O bottlenecks.

Silent SQLite Storage (smf.printd): Isolates debugging logs and error tracebacks directly to a structured SQLite database in the OS /tmp directory without filling up the terminal stdout buffer.

Native Type Ingestion: The FFI layer handles Python data type conversion to Rust strings directly (PyBytes, NoneType, and custom classes via slots __str__).

Python Print Compatible: Supporting conventional arguments such as sep, end, file, And flush.


Technical Performance Highlights

  1. Overhead & Speed: Reduces I/O interrupt overhead on massive log execution by moving the formatting and text writing process to the Rust native runtime.
  2. Crash & Traceback Capture: smf.printd automatically extracts stack traces and variable metadata when catching exceptions, saving them to a structured SQLite table.

Installation

# Pip install via wheel binary (Rust Toolchain required if building from source)
pip install smflog

Usage & API Reference

  1. High-Speed Terminal Output (smf.printf)
    Using an interface identical to print(), but executed in the Rust FFI layer:
import smf

# Custom separators & terminators
smf.printf("A", "B", "C", sep=" | ", end="\n---\n")

# Unpacking payload besar tanpa I/O lag
large_payload = [f"Data_{i}" for i in range(100_000)]
smf.printf(*large_payload, sep=", ")

# Stream redirection ke file object
with open("system.log", "a") as f:
    smf.printf("System status: OK", file=f, flush=True)
  1. Rust FFI Type Handling
    smflog handle Python data type conversions efficiently at the Rust level:
class CustomObject:
    def __str__(self):
        return "<CustomObject String Representation>"

# Handles PyBytes natively (escaped)
bytes = b"Hello\nWorld\x00"
smf.printf("Raw Bytes:", bytes)

# Handles NoneType & Custom Objects via __str__ slot
smf.printf("None Type:", None)
smf.printf("Custom Class:", CustomObject())
  1. Isolated SQLite Debug Logging (smf.printd)
    Save debug state and traceback to SQLite in OS temporary directory (/tmp):
try:
    result = 10 / 0
except Exception as e:
    # Automatically saved in SQLite without polluting the terminal stdout
    smf.printd("Division failed", e, level="ERROR")

Technical Architecture & PyO3 Integration

smflog designed as a high-performance C-Extension that bridges Python Global Interpreter Lock (GIL) with Rust Native Concurrency/I/O Engine.

  +---------------------------------------------------------------------------+
  |                               Python Layer                                |
  |  smf.printf(*args, sep, end, file, flush)      smf.printd(*args, level)   |
  +-------------------------------------+-------------------------------------+
                                        | PyO3 FFI Boundary
  +-------------------------------------v-------------------------------------+
  |                          Rust Native Engine (smf)                         |
  |                                                                           |
  |         +--------------------+             +--------------------+         |
  |         | Fast Type Resolver |             | Traceback Extractor|         |
  |         | (PyBytes/PyStr)    |             | (PyErr/Exception)  |         |
  |         +---------+----------+             +---------+----------+         |
  |                   |                                  |                    |
  |                   v                                  v                    |
  |         +--------------------+             +--------------------+         |
  |         | Direct OS stdout / |             | SQLite Connection  |         |
  |         | BufWriter Engine   |             | Pool (WAL Mode)    |         |
  |         +---------+----------+             +---------+----------+         |
  +-------------------|----------------------------------|--------------------+
                      v                                  v
               System Terminal                 OS /tmp/smflog/log.db (0o700)
  1. PyO3 Type Ingestion & FFI Conversion
    Crucial points in performance smflog is how Python data types are converted to Rust without excessive memory allocation overhead:
  • PyBytes Ingestion: Caught using obj.downcast::<PyBytes>(). Byte streams are processed directly at the Rust buffer level and non-printable characters are escaped automatically.
  • NoneType Isolation: Evaluated directly with C API preprocessing via obj.is_none(), avoiding Python attribute calls.
  • Custom Object Handling: Call slot __str__ on C-Struct Python via obj.str() only if the object is not a primitive type (string, int, float, bytes, bool).
  1. Lock & Thread Safety Design
  • smf.printf: Minimize reading duration GIL (Global Interpreter Lock). Concatenated string formatting (string concatenation) performed in the Rust thread layer before being executed to standard output.
  • smf.printd: Use SQLite Write-Ahead Logging (WAL) Mode which is stored in the OS's built-in temporary directory (/tmp or %TEMP%). Log writing is done in a thread-safe manner using an isolated connection pool to avoid database locked concerns when logs are sent in parallel/massively.

SQLite Database Schema (DDL)

To ensure that the smf.printd query can execute debugging logs and large-capacity tracebacks without causing performance degradation, the following SQLite database schema is automatically applied during module initialization:

-- Database Location: OS Temporary Directory (e.g., /tmp/smflog/log.db)
-- journal mode = WAL (Write Concurrency)
-- synchronous = NORMAL (Balanced Durability)
-- temp_store = MEMORY (RAM Temp Storage)

CREATE TABLE IF NOT EXISTS system_logs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    timestamp REAL,
    level TEXT,
    label TEXT,
    payload TEXT,
    traceback TEXT,
    caller_info TEXT
);",

SQLite Log Schema (smf.printd)

Log data is stored in the OS temporary database with the following schema:

Field Type Description
timestamp DATETIME Time the log was created (ISO-8601 UTC)
level TEXT Log severity (DEBUG, INFO, ERROR, WARN)
label TEXT Taken from the first string
payload TEXT Argument fusion result string
traceback TEXT Captured Python exception stack trace (If there are)
caller_info TEXT Location of the script caller that caused the error

License

This tool is distributed under the GPL License.

Download files

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

Source Distribution

smflog-1.0.5.tar.gz (23.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

smflog-1.0.5-cp39-abi3-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.9+Windows x86-64

smflog-1.0.5-cp39-abi3-manylinux_2_34_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

smflog-1.0.5-cp39-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file smflog-1.0.5.tar.gz.

File metadata

  • Download URL: smflog-1.0.5.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for smflog-1.0.5.tar.gz
Algorithm Hash digest
SHA256 697a96f3537b3a23783274d823ea256627275b76a9f46a46279bbdf2868fd564
MD5 4ef058731432ab70a3c28d7ffe43c439
BLAKE2b-256 d532ecb30d0fa8e25f96672f363a9b004114d4533b8debec5c851370d96d0503

See more details on using hashes here.

Provenance

The following attestation bundles were made for smflog-1.0.5.tar.gz:

Publisher: test-build-and-release.yaml on StormWorld0/smflog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smflog-1.0.5-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: smflog-1.0.5-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for smflog-1.0.5-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 930616dce50eda25e7a9e8ada39cc9eb1563195dce1aa4ad654480b031c6da94
MD5 a64d6265f10702670331fb65450876fe
BLAKE2b-256 d9eb3c7a17678a259efb1b7f37a5ca30dc86c2bfcd7480ebff941d41169e82ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for smflog-1.0.5-cp39-abi3-win_amd64.whl:

Publisher: test-build-and-release.yaml on StormWorld0/smflog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smflog-1.0.5-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for smflog-1.0.5-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f4a2a377189bbaee4a74fc54a678aa0287a73ed9a59f5f3f0b6118727f414e14
MD5 b7ed9f8685c58a48d81821cb421d5d39
BLAKE2b-256 721fe4a345797a24ea78d5ca0536595ad0d3b4b7b01b6c8f66ce8e4976c2d692

See more details on using hashes here.

Provenance

The following attestation bundles were made for smflog-1.0.5-cp39-abi3-manylinux_2_34_x86_64.whl:

Publisher: test-build-and-release.yaml on StormWorld0/smflog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smflog-1.0.5-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for smflog-1.0.5-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 15749c21ae2281a27d6bac4afdb2794500ca75417c421063f098d1580a410013
MD5 1240f6bc26cb796ed831a0f16cce3202
BLAKE2b-256 9e797953f283fc696fd2f81a002838717944610f4bc3248becefe2f4e3e5ef3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for smflog-1.0.5-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: test-build-and-release.yaml on StormWorld0/smflog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page