Skip to main content

Privlog

PyPI Python License

A privacy-aware linter for Python projects, designed to catch accidental leaks of sensitive data in logs and print statements before they reach production.

privlog is built to be a developer's first line of defense, integrating directly into your local workflow and CI/CD pipelines to enforce logging hygiene.

Why Privlog?

Accidentally logging sensitive data is a common source of security and privacy issues in production systems. Tokens, user identifiers, request bodies, and other sensitive values often end up in logs during development and debugging.

Privlog helps detect these risks early by scanning Python code for logging patterns that may expose sensitive data.

Quick Example

Given a file app/auth.py:

import logging

def reauthenticate_user(user_email):
    # ...
    logging.info(f"Initiating re-authentication for {user_email}")
    # ...

Running privlog . will produce the following error:

app/auth.py:5:5 [ERROR]    PL2101 Sensitive identifier "user_email" passed to log. Hash, pseudonymize, or omit before logging.

Features

  • High-Precision AST Analysis: Goes beyond simple regex to parse Python code, understanding variable names inside f-strings, .format() calls, and more.
  • Severity System: Differentiates between definite leaks (ERROR) and suspicious patterns that require manual review (WARNING), preventing false positives from breaking your build.
  • Built-in Heuristics: Flags risky patterns like logging entire dictionaries (extra=...) or json.dumps() output.
  • print() Statement Detection: Catches sensitive data in leftover print() statements, a common source of leaks.
  • CI/CD Friendly: Exits with a non-zero code only on ERROR findings, allowing warnings to be reviewed without blocking development.
  • Configurable & Extensible: Teach privlog about your project's custom logging functions via a simple pyproject.toml configuration.

Installation

It is highly recommended to install privlog within a project's virtual environment to avoid dependency conflicts.

Recommended (Virtual Environment):

# 1. Create and activate a virtual environment in your project directory
python -m venv .venv
source .venv/bin/activate  # On Windows, use: .venv\Scripts\activate

# 2. Install privlog
pip install privlog

Global Installation: While not recommended for most workflows, you can also install it globally:

pip install privlog

Usage

Once installed, you can run privlog against a specific path, or run it by itself to scan the current directory.

Note: privlog automatically ignores common dependency and build directories (like .venv, site-packages, build, etc.) to reduce noise.

Default (Errors Only)

By default, privlog only reports high-confidence ERRORs. If any are found, it will exit with a non-zero code, failing your build.

# Scan a specific directory
privlog /path/to/your/project

# Or, from inside a project, scan the current directory
privlog .

If only warnings are found, the command will pass and provide a helpful message:

✅ privlog passed. No errors found.
  (Warnings were found. Run with -w to show them)

Show Warnings

To see both ERRORs and WARNINGs, use the -w or --warnings flag.

# Scan a specific directory with warnings
privlog -w /path/to/your/project

# Or, from inside a project, scan the current directory with warnings
privlog -w .

This will display all findings, color-coded by severity, but will still only fail the build if ERRORs are present.

Other Flags

  • --verbose / -v: Enables verbose output from the underlying semgrep scanner. This is useful for debugging rules and understanding which files semgrep is scanning or skipping. By default, privlog always shows a high-level progress indicator; this flag provides much more detail about the semgrep scanning phase.
  • --version: Display the installed version of privlog.

Configuring Custom Wrappers

You can teach privlog to recognize your own custom logging functions. In your project's pyproject.toml file, add a [tool.privlog.custom_wrappers] section.

For each custom function, specify its name and which of its keyword arguments should be treated as sensitive, along with the desired severity (ERROR or WARNING).

Example pyproject.toml:

[tool.privlog.custom_wrappers]
# For a function call like: audit(actor_id=user.id, event="login")
audit = { actor_id = "ERROR" }

# For a function call like: log_event("payment_failed", details=evt)
log_event = { details = "WARNING" }

privlog will automatically find and use this configuration when you run it.


Status

Privlog is currently in early development (v0.2.2). Feedback and contributions are welcome.


For Developers

To set up a development environment to contribute to privlog:

# 1. Clone the repository and navigate into the directory
git clone https://github.com/privlog-dev/privlog.git
cd privlog

# 2. Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate

# 3. Install the tool in editable mode with development dependencies
pip install -e .

Metadata

Release files for privlog 0.2.2

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

Source distribution (sdist)

Source distribution for privlog 0.2.2
File Size Uploaded Provenance
privlog-0.2.2.tar.gz 14.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for privlog 0.2.2
File Interpreter ABI Platform
privlog-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.4 kB

Release files / privlog-0.2.2.tar.gz

Download URL privlog-0.2.2.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
346cbaaed84726aa677f27cec5a7df22de5805926aae970bde2e4698664c7d0c
BLAKE2b-256 checksum
How to use checksums
626c0a92c9fe55890790b9d8e1236670826c12b13cb9a78f0f63b853e444e7fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / privlog-0.2.2-py3-none-any.whl

Download URL privlog-0.2.2-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcd63ed96b915dd5aaf5c7e7a06664b4451fc5f3ae06bb11597c48b9fb27f420
BLAKE2b-256 checksum
How to use checksums
32797015721b787eaf37b651cc2ede9b7e0f50ad669ea974e0396115a0950235
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for privlog 0.2.2

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.

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