Registry / testing / flake8-logging-format

flake8-logging-format

JSON →
library2024.24.12pypypiunverified

flake8-logging-format is a Flake8 plugin designed to validate the format strings used in Python's standard `logging` calls. It helps prevent common errors like argument count mismatches or type mismatches between format specifiers and provided arguments. The current version is 2024.24.12, and it follows a calver-like release schedule based on active development.

pip install flake8-logging-format
INSTALL
IMPORT
SIG · FLAKE8-LOGGING-FOR
F
flake8-logging-format
testingpythonv2024.24.12
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2024.24.12 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Flake8 Plugin Availability
Install 'flake8-logging-format' and run 'flake8'.
This library is a Flake8 plugin and is not imported directly into Python code. Its functionality is automatically enabled when 'flake8' is run after installation, extending Flake8's linting capabilities.

This example demonstrates how `flake8-logging-format` catches common errors in logging calls. After installing the plugin, save the code as `main.py` and run `flake8 main.py` from your terminal. The plugin will automatically identify issues like argument count mismatches or type discrepancies based on format specifiers.

import logging # Configure a basic logger for demonstration logging.basicConfig(level=logging.INFO) def process_user(user_id, username): logging.info("Processing user: %s (ID: %d)", username, user_id) # Correct usage logging.warning("User with ID %s did something questionable", user_id) # LGA001: %s expects str, but user_id is int logging.error("Failed operation on user %s", username, user_id) # LGA001: too many args (expected 1 for %s, got 2) logging.info("Data: %s %s", "value1") # LGA001: too few args (expected 2 for %s %s, got 1) # Example usage to trigger the logging calls (output is to console, but errors caught by flake8) process_user(123, "john.doe") # To run this with flake8-logging-format, save it as `main.py` and run: # pip install flake8 flake8-logging-format # flake8 main.py # # Expected output for `flake8 main.py`: # main.py:8:5: LGA001 Format string argument count mismatch: '%s' for 'user_id' expects str, but got int. # main.py:9:5: LGA001 Format string argument count mismatch: '%s' for 'username' expects 1 argument, but 2 were given. # main.py:10:5: LGA001 Format string argument count mismatch: '%s %s' for 'value1' expects 2 arguments, but 1 was given.
Debug
Known issues
gotchaThis library is a plugin for Flake8. It will not work if Flake8 is not installed alongside it, or if it's installed in an environment where Flake8 is not active. Ensure both are installed in the same virtual environment.
fix
Run `pip install flake8 flake8-logging-format` to ensure both the linter and its plugin are present and correctly linked.
affects: All
gotchaThe default logging format regular expression (`log-format-expressions`) might not cover all custom logging practices. If you use unusual format specifiers or custom logging functions beyond standard Python `logging` or `printf`-style formatting, the plugin might produce false negatives (miss errors) or false positives (report non-existent errors).
fix
Review the `log-format-expressions` configuration option. If your project uses non-standard logging formats, you may need to define custom regular expressions in your `pyproject.toml`, `setup.cfg`, or `tox.ini` under the `[flake8]` section.
affects: All
Upgrade
Version history
2024.24.12latest on PyPI · released Jun 11, 2024
Audit
Dependencies
flake8requiredThis library is a plugin for Flake8 and requires it to function.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
2
Resources
flake8-logging-format — pip install flake8-logging-format · libregistry