{"id":20126815,"url":"https://github.com/cc-d/logf","last_synced_at":"2025-05-06T17:35:35.379Z","repository":{"id":176993870,"uuid":"657708311","full_name":"cc-d/logf","owner":"cc-d","description":"The @logf() decorator enables low effort, high customization logging of the performance, args/kwargs, enter/exit, return value, and exceptions of any function it is applied to.","archived":false,"fork":false,"pushed_at":"2024-07-29T04:22:56.000Z","size":185,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-13T20:17:13.386Z","etag":null,"topics":["logging","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cc-d.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-23T16:52:43.000Z","updated_at":"2024-09-04T07:45:58.000Z","dependencies_parsed_at":"2024-01-06T11:28:20.034Z","dependency_job_id":"b9e268fa-d11b-4f67-8e08-f54d83d94746","html_url":"https://github.com/cc-d/logf","commit_stats":null,"previous_names":["cc-d/logf"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Flogf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Flogf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Flogf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Flogf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cc-d","download_url":"https://codeload.github.com/cc-d/logf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224517261,"owners_count":17324409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logging","python","python3"],"created_at":"2024-11-13T20:17:44.371Z","updated_at":"2024-11-13T20:17:44.983Z","avatar_url":"https://github.com/cc-d.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# logfunc - @logf()\n\n`@logf()` is a Python decorator designed for uncomplicated and immediate addition of logging to functions. Its main goal is to provide developers with a tool that can be added quickly to any function and left in place without further adjustments.\n\nI originally made `@logf()` for my own use, but I hope it can be useful to others as well.\n\n## Highlights\n\n- **Async Support**: Incorporated from version 1.6 onwards.\n- **Broad Python 3 Compatibility**: Designed to work seamlessly across multiple Python 3 versions,\n- **Effortless Logging**: Implement logging without disrupting the flow of your code.\n- **Leave-and-Forget**: Once integrated, no further adjustments are needed.\n- **Encourages Logic Compartmentalization**.\n- **Customizable**: Numerous settings available for tailoring logging behavior to specific needs.\n- **Environment Variables**: Overriding default settings made easy with environment variables.\n- **Log Exceptions**: Option to log exceptions before they are raised.\n\n## Usage\n\n### Installation\n\nTo integrate `@logf()` into your projects:\n\n```sh\npip install logfunc\n```\n\n### Importing\n\nSimply import the decorator to start using it:\n\n```python\nfrom logfunc import logf\n```\n\n### Basic Usage\n\nApply the `@logf()` decorator to functions you intend to log:\n\n```python\nfrom logfunc import logf\n\n@logf()\ndef concatenate_strings(str1: str, str2: str) -\u003e str:\n    return str1 + str2\n```\n\nThis setup ensures automatic logging of function name, parameters, return values, and execution time.\n\n### @logf() args\n\n- `level`: Set the log level (DEBUG, INFO, WARNING, etc.).\n- `log_args` \u0026 `log_return`: Control whether to log arguments and return values.\n- `max_str_len`: Limit the length of logged strings.\n- `log_exec_time`: Option to log the execution time.\n- `single_msg`: Consolidate all log data into a single message.\n- `use_print`: Choose to `print()` log messages instead of using standard logging.\n- `log_stack_info`: Pass `stack_info=$x` to `.log()` but not print\n- `use_logger`: Pass a logger name or logger object to use instead of logging.log\n- `identifier`: Add a unique identifier to enter/exit log messages.\n\n**print_all** used to be an env var, now just unset LOGF_LEVEL and set USE_PRINT=True for the same effect.\n\n### Environment Variable Overrides\n\nModify the behavior of `@logf()` using environment variables:\n\n| Env Var            | Example Values       |\n| ------------------ | -------------------- |\n| LOGF_LEVEL         | DEBUG, INFO, WARNING |\n| LOGF_MAX_STR_LEN   | 10, 50, 10000000     |\n| LOGF_SINGLE_MSG    | True, False          |\n| LOGF_USE_PRINT     | True, False          |\n| LOGF_STACK_INFO    | True, False          |\n| LOGF_LOG_EXEC_TIME | True, False          |\n| LOGF_LOG_ARGS      | True, False          |\n| LOGF_LOG_RETURN    | True, False          |\n| LOGF_USE_LOGGER    | 'logger_name'        |\n| LOGF_LOG_LEVEL     | DEBUG, INFO, WARNING |\n| LOGF_IDENTIFIER    | True, False          |\n\nSee the following output for an example of how an env var will affect `@logf()` behaviour:\n\nWith `LOGF_USE_PRINT=True`:\n\n```\nmym2@Carys-MacBook-Pro logf % gitpoll ~/test\nRunning once...\n-\u003e __init__()[CwKVbK] | (\u003cCmdExec \u003e, 'git rev-parse --abbrev-ref HEAD') {}\n\u003c- __init__()[CwKVbK] 0.0048s | None\n-\u003e __init__()[BIimGf] | (\u003cCmdExec \u003e, 'git config --get branch.test.remote') {}\n\u003c- __init__()[BIimGf] 0.0040s | None\n-\u003e __init__()[ED1XW0] | (\u003cCmdExec \u003e, 'git config --get branch.test.merge') {}\n\u003c- __init__()[ED1XW0] 0.0039s | None\n-\u003e __init__()[dsPXjJ] | (\u003cCmdExec \u003e, 'git rev-parse refs/remotes//') {}\n\u003c- __init__()[dsPXjJ] 0.0044s | None\n-\u003e __init__()[5rkgc9] | (\u003cCmdExec \u003e, 'git rev-parse HEAD') {}\n\u003c- __init__()[5rkgc9] 0.0037s | None\n-\u003e __init__()[GDti62] | (\u003cCmdExec \u003e, 'git fetch') {}\n\u003c- __init__()[GDti62] 1.1160s | None\n```\n\nWith `LOGF_SINGLE_MSG=True`:\n\n```\nmym2@Carys-MacBook-Pro logf % gitpoll ~/test\nRunning once...\n__init__() 0.0050s | (\u003cCmdExec \u003e, 'git rev-parse --abbrev-ref HEAD') {} | None\n__init__() 0.0041s | (\u003cCmdExec \u003e, 'git config --get branch.test.remote') {} | None\n__init__() 0.0041s | (\u003cCmdExec \u003e, 'git config --get branch.test.merge') {} | None\n__init__() 0.0041s | (\u003cCmdExec \u003e, 'git rev-parse refs/remotes//') {} | None\n__init__() 0.0038s | (\u003cCmdExec \u003e, 'git rev-parse HEAD') {} | None\n__init__() 1.0993s | (\u003cCmdExec \u003e, 'git fetch') {} | None\n```\n\n### Real-world Examples\n\nHere are a couple of real-world examples of `@logf()` usage:\n\n```python\nfrom logfunc import logf\n\n\n# Database operations\n@logf(level='ERROR')\ndef db_insert(item):\n    # Insert item into database\n    pass\n\n# Asynchronous tasks in an application\n@logf()\nasync def fetch_data(url):\n    # Fetch data from URL asynchronously\n    return data\n```\n\n## Testing\n\nActivate/create your venv with `python3 -m venv venv` and `source venv/bin/activate` if you haven't already.\n\nRun `pip install -r requirements_dev.txt` to install the testing dependencies.\n\nRun `pytest tests.py` to run the tests.\n\nOutput should look like this:\n\n```sh\n---------- coverage: platform darwin, python 3.11.5-final-0 ----------\nName                  Stmts   Miss  Cover   Missing\n---------------------------------------------------\nlogfunc/__init__.py       2      0   100%\nlogfunc/config.py        59      0   100%\nlogfunc/defaults.py       2      0   100%\nlogfunc/main.py          69      0   100%\nlogfunc/msgs.py           8      0   100%\nlogfunc/utils.py         35      0   100%\nlogfunc/version.py        1      0   100%\n---------------------------------------------------\nTOTAL                   176      0   100%\n\n\n==================================== 25 passed in 0.06s\n```\n\nYou can also just run the `tests.py` file directly.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue.\n\n## License\n\nMIT\n\n## Contact\n\nccarterdev@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcc-d%2Flogf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcc-d%2Flogf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcc-d%2Flogf/lists"}