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 ใใกใคใซใใ่ฆงใใ ใใใ