Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logkit-macro

logkit-macros is a proc-macro attribute that automatically expands ? operators in functions and logs errors individually in Rust.
logkit-macros は Rust で関数内の ? 演算子を自動的に展開し、エラー時に個別にログ出力する 属性マクロ (proc-macro) です。

📦 Features

  • 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 を使って関数単位でログを出力する

Example

#[try_with_log]
fn multi_try_fn() -> Result<(), anyhow::Error> {
    step1()?;  // logs if an error occurs
    step2()?;
    Ok(())
}

📚 Requirements

  • Rust 1.70+ (with Cargo)

🚀 Getting Started

  1. Add to Cargo.toml:
[dependencies]
logkit-macros = { git = "https://github.com/show-t/rust-logkit-macros" }

📖 Usage

  1. Initialize tracing_subscriber:
tracing_subscriber::fmt::init();
  1. 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(())
}

📁 Project Structure

.
├── 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

📄 License

This project is licensed under the MIT License.
本プロジェクトは MIT ライセンスのもとで公開されています。

See the LICENSE file for more details.
詳細は LICENSE ファイルをご覧ください。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages