{"id":19710030,"url":"https://github.com/fast/logcall","last_synced_at":"2025-04-29T17:31:08.936Z","repository":{"id":182817459,"uuid":"669149814","full_name":"fast/logcall","owner":"fast","description":"An attribute macro that logs the function return value","archived":false,"fork":false,"pushed_at":"2025-01-30T06:48:13.000Z","size":54,"stargazers_count":23,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T18:50:35.982Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.rs/logcall","language":"Rust","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/fast.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-07-21T13:13:32.000Z","updated_at":"2025-03-25T05:35:27.000Z","dependencies_parsed_at":"2024-06-16T13:59:22.939Z","dependency_job_id":"eca32cde-5222-4ba8-90a1-a5716f1c108d","html_url":"https://github.com/fast/logcall","commit_stats":null,"previous_names":["andylokandy/logfn","andylokandy/logcall","fast/logcall"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Flogcall","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Flogcall/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Flogcall/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Flogcall/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fast","download_url":"https://codeload.github.com/fast/logcall/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251549176,"owners_count":21607365,"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":[],"created_at":"2024-11-11T22:06:03.897Z","updated_at":"2025-04-29T17:31:08.923Z","avatar_url":"https://github.com/fast.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Logcall\n\n[![Crates.io](https://img.shields.io/crates/v/logcall?style=flat-square\u0026logo=rust)](https://crates.io/crates/logcall)\n[![Downloads](https://img.shields.io/crates/d/logcall?style=flat-square\u0026logo=rust)](https://crates.io/crates/logcall)\n[![Documentation](https://img.shields.io/docsrs/logcall?style=flat-square\u0026logo=rust)](https://docs.rs/logcall/)\n[![CI Status](https://img.shields.io/github/actions/workflow/status/fast/logcall/ci.yml?style=flat-square\u0026logo=github)](https://github.com/fast/logcall/actions)\n[![License](https://img.shields.io/crates/l/logcall?style=flat-square\u0026logo=)](https://crates.io/crates/logcall)\n\nLogcall is a Rust procedural macro crate designed to automatically log function calls, their inputs, and their outputs. This macro facilitates debugging and monitoring by providing detailed logs of function executions with minimal boilerplate code.\n\nThis is a re-implementation of the [`log-derive`](https://crates.io/crates/log-derive) crate with [`async-trait`](https://crates.io/crates/async-trait) compatibility.\n\n## Installation\n\nAdd `logcall` to your `Cargo.toml`:\n\n```toml\n[dependencies]\nlogcall = \"0.1\"\n```\n\n## Usage\n\nImport the `logcall` crate and use the macro to annotate your functions:\n\n```rust\nuse logcall::logcall;\nuse logforth::append;\nuse logforth::filter::EnvFilter;\n\n/// Logs the function call at the default `debug` level.\n#[logcall]\nfn add(a: i32, b: i32) -\u003e i32 {\n    a + b\n}\n\n/// Logs the function call at the `info` level.\n#[logcall(\"info\")]\nfn multiply(a: i32, b: i32) -\u003e i32 {\n    a * b\n}\n\n/// Logs `Ok` results at the `info` level and `Err` results at the `error` level.\n#[logcall(ok = \"info\", err = \"error\")]\nfn divide(a: i32, b: i32) -\u003e Result\u003ci32, String\u003e {\n    if b == 0 {\n        Err(\"Division by zero\".to_string())\n    } else {\n        Ok(a / b)\n    }\n}\n\n/// Logs errors at the `error` level. No log output for `Ok` variant.\n#[logcall(err = \"error\")]\nfn divide2(a: usize, b: usize) -\u003e Result\u003cusize, String\u003e {\n    if b == 0 {\n        Err(\"Division by zero\".to_string())\n    } else {\n        Ok(a / b)\n    }\n}\n\n/// Logs the function call with custom input logging format.\n#[logcall(input = \"a = {a:?}, ..\")]\nfn subtract(a: i32, b: i32) -\u003e i32 {\n    a - b\n}\n\nfn main() {\n    logforth::builder()\n        .dispatch(|d| {\n            d.filter(EnvFilter::from_default_env_or(\"trace\"))\n                .append(append::Stderr::default())\n        })\n        .apply();\n\n    add(2, 3);\n    multiply(2, 3);\n    divide(2, 0).ok();\n    divide2(2, 0).ok();\n    subtract(3, 2);\n}\n```\n\n### Log Output\n\nWhen the `main` function runs, it initializes the logger and logs each function call as specified:\n\n```plaintext\n2024-12-22T07:02:59.787586+08:00[Asia/Shanghai] DEBUG main: main.rs:6 main::add(a = 2, b = 3) =\u003e 5\n2024-12-22T07:02:59.816839+08:00[Asia/Shanghai]  INFO main: main.rs:12 main::multiply(a = 2, b = 3) =\u003e 6\n2024-12-22T07:02:59.816929+08:00[Asia/Shanghai] ERROR main: main.rs:18 main::divide(a = 2, b = 0) =\u003e Err(\"Division by zero\")\n2024-12-22T07:02:59.816957+08:00[Asia/Shanghai] ERROR main: main.rs:28 main::divide2(a = 2, b = 0) =\u003e Err(\"Division by zero\")\n2024-12-22T07:02:59.816980+08:00[Asia/Shanghai] DEBUG main: main.rs:38 main::subtract(a = 3, ..) =\u003e 1\n```\n\n## Customization\n\n- **Default Log Level**: If no log level is specified, `logcall` logs at the `debug` level:\n  ```rust,ignore\n  #[logcall]\n  ```\n- **Specify Log Level**: Use the macro parameters to specify log level:\n  ```rust,ignore\n  #[logcall(\"info\")]\n- **Specify Log Levels for `Result`**: Use the `ok` and `err` parameters to specify log levels for `Ok` and `Err` variants:\n  ```rust,ignore\n  #[logcall(err = \"error\")]\n  #[logcall(ok = \"info\", err = \"error\")]\n  ```\n- **Customize Input Logging**: Use the `input` parameter to customize the input log format:\n  ```rust,ignore\n  #[logcall(input = \"a = {a:?}, ..\")]\n  #[logcall(\"info\", input = \"a = {a:?}, ..\")]\n  #[logcall(ok = \"info\", err = \"error\", input = \"a = {a:?}, ..\")]\n  ```\n\n## Minimum Supported Rust Version (MSRV)\n\nThis crate is built against the latest stable release, and its minimum supported rustc version is 1.80.0.\n\nThe policy is that the minimum Rust version required to use this crate can be increased in minor version updates. For example, if Logcall 1.0 requires Rust 1.20.0, then Logcall 1.0.z for all values of z will also require Rust 1.20.0 or newer. However, Logcall 1.y for y \u003e 0 may require a newer minimum version of Rust.\n\n## Contributing\n\nContributions are welcome! Please submit pull requests or open issues to improve the crate.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Flogcall","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffast%2Flogcall","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Flogcall/lists"}