{"id":5931,"library":"flake8-logging-format","title":"flake8-logging-format","description":"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.","status":"active","version":"2024.24.12","language":"en","source_language":"en","source_url":"https://github.com/globality-corp/flake8-logging-format","tags":["flake8","linter","logging","code quality","static analysis"],"install":[{"cmd":"pip install flake8-logging-format","lang":"bash","label":"Install plugin"}],"dependencies":[{"reason":"This library is a plugin for Flake8 and requires it to function.","package":"flake8","optional":false}],"imports":[{"note":"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.","symbol":"Flake8 Plugin Availability","correct":"Install 'flake8-logging-format' and run 'flake8'."}],"quickstart":{"code":"import logging\n\n# Configure a basic logger for demonstration\nlogging.basicConfig(level=logging.INFO)\n\ndef process_user(user_id, username):\n    logging.info(\"Processing user: %s (ID: %d)\", username, user_id) # Correct usage\n    logging.warning(\"User with ID %s did something questionable\", user_id) # LGA001: %s expects str, but user_id is int\n    logging.error(\"Failed operation on user %s\", username, user_id) # LGA001: too many args (expected 1 for %s, got 2)\n    logging.info(\"Data: %s %s\", \"value1\") # LGA001: too few args (expected 2 for %s %s, got 1)\n\n# Example usage to trigger the logging calls (output is to console, but errors caught by flake8)\nprocess_user(123, \"john.doe\")\n\n# To run this with flake8-logging-format, save it as `main.py` and run:\n# pip install flake8 flake8-logging-format\n# flake8 main.py\n#\n# Expected output for `flake8 main.py`:\n# main.py:8:5: LGA001 Format string argument count mismatch: '%s' for 'user_id' expects str, but got int.\n# main.py:9:5: LGA001 Format string argument count mismatch: '%s' for 'username' expects 1 argument, but 2 were given.\n# main.py:10:5: LGA001 Format string argument count mismatch: '%s %s' for 'value1' expects 2 arguments, but 1 was given.\n","lang":"python","description":"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."},"warnings":[{"fix":"Run `pip install flake8 flake8-logging-format` to ensure both the linter and its plugin are present and correctly linked.","message":"This 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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"The 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).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}