logkit-macros is a proc-macro attribute that automatically expands ? operators in functions and logs errors individually in Rust.
logkit-macros は Rust で関数内の ? 演算子を自動的に展開し、エラー時に個別にログ出力する 属性マクロ (proc-macro) です。
- Attach
#[try_with_log]to a function and all?operators inside it are transformed
#[try_with_log]を関数につけることにより、関数内のすべての?演算子を変換 - When an error occurs, logs are output per function using
tracing
エラーが発生した場合、tracingを使って関数単位でログを出力する
#[try_with_log]
fn multi_try_fn() -> Result<(), anyhow::Error> {
step1()?; // logs if an error occurs
step2()?;
Ok(())
}- Rust 1.70+ (with Cargo)
- Add to Cargo.toml:
[dependencies]
logkit-macros = { git = "https://github.com/show-t/rust-logkit-macros" }- Initialize tracing_subscriber:
tracing_subscriber::fmt::init();- Add
#[try_with_log]to the function:
use logkit_macros::try_with_log;
use anyhow::Result;
#[try_with_log]
fn example() -> Result<()> {
do_something()?; // logs on error
Ok(())
}.
├── src/ # Rust source files
│ ├── macros_impl/ # Macro implementation
│ └── lib.rs # Crate public interface
├── target/ # Compiled Rust output
├── cargo.toml # Cargo configuration
├── .gitignore
├── LICENSE
└── README.md # Project documentation
This project is licensed under the MIT License.
本プロジェクトは MIT ライセンスのもとで公開されています。
See the LICENSE file for more details.
詳細は LICENSE ファイルをご覧ください。