-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from baoyachi/issue/21
Fix bug
- Loading branch information
Showing
7 changed files
with
161 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: cargo | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 10 | ||
labels: | ||
- "\U0001F4E6 dependencies" | ||
- package-ecosystem: github-actions | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 10 | ||
labels: | ||
- "\U0001F4E6 dependencies" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "simple-log-derive" | ||
version.workspace = true | ||
authors.workspace = true | ||
description.workspace = true | ||
edition.workspace = true | ||
keywords.workspace = true | ||
readme.workspace = true | ||
categories.workspace = true | ||
documentation.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
|
||
[dependencies] | ||
syn = "2" | ||
quote = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::{parse_macro_input, Ident}; | ||
|
||
#[proc_macro] | ||
pub fn log_target_derive(input: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(input as Ident); | ||
|
||
const LOG_LEVELS: [&str; 5] = ["trace", "debug", "info", "warn", "error"]; | ||
|
||
let mut parts = Vec::new(); | ||
|
||
for level in LOG_LEVELS.iter() { | ||
let log_target = Ident::new(&format!("{}_{}", level, input), input.span()); | ||
let log_level = match *level { | ||
"trace" => quote!($crate::log::Level::Trace), | ||
"debug" => quote!($crate::log::Level::Debug), | ||
"info" => quote!($crate::log::Level::Info), | ||
"warn" => quote!($crate::log::Level::Warn), | ||
"error" => quote!($crate::log::Level::Error), | ||
_ => unreachable!(), | ||
}; | ||
|
||
let expand = quote! { | ||
#[macro_export] | ||
macro_rules! #log_target { | ||
($($arg:tt)*) => ($crate::log::log!(target: stringify!(#input), #log_level, $($arg),*)); | ||
} | ||
}; | ||
parts.push(expand); | ||
} | ||
|
||
let combined = quote! { | ||
#(#parts)* | ||
}; | ||
|
||
TokenStream::from(combined) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters