lazy-log-formatter


Namelazy-log-formatter JSON
Version 0.4.4 PyPI version JSON
download
home_pagehttps://github.com/dmar1n/lazy-log-formatter
SummaryA pre-commit script to make log lines lazzier
upload_time2024-11-30 17:13:38
maintainerNone
docs_urlNone
authorDaniel Marín
requires_python<4.0,>=3.10
licenseApache-2.0
keywords pre-commit logging pylint lazy logging w1203 f-strings code-quality linting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Lazy log formatter

Pre-commit hook to automatically detect and convert f-strings in Python code used in log calls to lazy log calls, 
following W1203 Pylint rule:

https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/logging-fstring-interpolation.html

## Usage

To use with pre-commit, add the following to your `.pre-commit-config.yaml`:

```yaml
- repo: https://github.com/dmar1n/lazy-log-formatter
  rev: 0.4.2
  hooks:
    - id: lazy-log-formatter
    args: ['--fix']
```

## Options

- `--fix`: Automatically fix f-strings used in log calls to lazy log calls.

## Examples

If the `--fix` option is used, the hook will convert f-strings in log calls to lazy log calls, as follows:

```python
# Before
logger.info(f'Hello {name}')

# After
logger.info('Hello %s', name)
```

```python
# Before
logger.info(f'Hello {name} {surname}')

# After
logger.info('Hello %s %s', name, surname)
```

## Current limitations

- Only works with `logging` module. Other logging libraries might not work as expected, such as `loguru`.
- Multi-line f-strings in the editor are not supported yet (they are simply ignored).

For `loguru`, see [Lazy evaluation of expensive functions](https://loguru.readthedocs.io/en/stable/overview.html#lazy-evaluation-of-expensive-functions):

```python
logger.opt(lazy=True).debug("If sink level <= DEBUG: {x}", x=lambda: expensive_function(2**64))
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dmar1n/lazy-log-formatter",
    "name": "lazy-log-formatter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "pre-commit, logging, pylint, lazy logging, W1203, f-strings, code-quality, linting",
    "author": "Daniel Mar\u00edn",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b7/b7/6c5138df427ab65ed28bb19151721e08b19a04dd39c9fbb2c6de2980bd0c/lazy_log_formatter-0.4.4.tar.gz",
    "platform": null,
    "description": "# Lazy log formatter\n\nPre-commit hook to automatically detect and convert f-strings in Python code used in log calls to lazy log calls, \nfollowing W1203 Pylint rule:\n\nhttps://pylint.readthedocs.io/en/stable/user_guide/messages/warning/logging-fstring-interpolation.html\n\n## Usage\n\nTo use with pre-commit, add the following to your `.pre-commit-config.yaml`:\n\n```yaml\n- repo: https://github.com/dmar1n/lazy-log-formatter\n  rev: 0.4.2\n  hooks:\n    - id: lazy-log-formatter\n    args: ['--fix']\n```\n\n## Options\n\n- `--fix`: Automatically fix f-strings used in log calls to lazy log calls.\n\n## Examples\n\nIf the `--fix` option is used, the hook will convert f-strings in log calls to lazy log calls, as follows:\n\n```python\n# Before\nlogger.info(f'Hello {name}')\n\n# After\nlogger.info('Hello %s', name)\n```\n\n```python\n# Before\nlogger.info(f'Hello {name} {surname}')\n\n# After\nlogger.info('Hello %s %s', name, surname)\n```\n\n## Current limitations\n\n- Only works with `logging` module. Other logging libraries might not work as expected, such as `loguru`.\n- Multi-line f-strings in the editor are not supported yet (they are simply ignored).\n\nFor `loguru`, see [Lazy evaluation of expensive functions](https://loguru.readthedocs.io/en/stable/overview.html#lazy-evaluation-of-expensive-functions):\n\n```python\nlogger.opt(lazy=True).debug(\"If sink level <= DEBUG: {x}\", x=lambda: expensive_function(2**64))\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A pre-commit script to make log lines lazzier",
    "version": "0.4.4",
    "project_urls": {
        "Homepage": "https://github.com/dmar1n/lazy-log-formatter",
        "Repository": "https://github.com/dmar1n/lazy-log-formatter"
    },
    "split_keywords": [
        "pre-commit",
        " logging",
        " pylint",
        " lazy logging",
        " w1203",
        " f-strings",
        " code-quality",
        " linting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0ecb03261184e5a2cf1164a18b86e71d7bb0e3c4811a1e6ef877744d701108d",
                "md5": "4604859ca6b499c07f5f000af9b58053",
                "sha256": "d5e8eecedd062f040bfd00d555e47c900e0b2d919934a91e30a4d8abdcbb0688"
            },
            "downloads": -1,
            "filename": "lazy_log_formatter-0.4.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4604859ca6b499c07f5f000af9b58053",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 8306,
            "upload_time": "2024-11-30T17:13:20",
            "upload_time_iso_8601": "2024-11-30T17:13:20.683489Z",
            "url": "https://files.pythonhosted.org/packages/b0/ec/b03261184e5a2cf1164a18b86e71d7bb0e3c4811a1e6ef877744d701108d/lazy_log_formatter-0.4.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7b76c5138df427ab65ed28bb19151721e08b19a04dd39c9fbb2c6de2980bd0c",
                "md5": "0d6d1c763d82cfc839a149728113f1a4",
                "sha256": "d1e3dc041978be2c85a24159e416b0fdba693c8ee173ce5dda53de8a7fd0819c"
            },
            "downloads": -1,
            "filename": "lazy_log_formatter-0.4.4.tar.gz",
            "has_sig": false,
            "md5_digest": "0d6d1c763d82cfc839a149728113f1a4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 7405,
            "upload_time": "2024-11-30T17:13:38",
            "upload_time_iso_8601": "2024-11-30T17:13:38.749301Z",
            "url": "https://files.pythonhosted.org/packages/b7/b7/6c5138df427ab65ed28bb19151721e08b19a04dd39c9fbb2c6de2980bd0c/lazy_log_formatter-0.4.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-30 17:13:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dmar1n",
    "github_project": "lazy-log-formatter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "lazy-log-formatter"
}
        
Elapsed time: 1.58734s