big heckin reworkerino to use the standard #line directive as per spec

This commit is contained in:
Noah Santschi-Cooney 2022-04-03 21:31:18 +01:00
parent cb7c9b8b49
commit d3365c3bff
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
52 changed files with 574 additions and 398 deletions

View file

@ -0,0 +1,12 @@
[package]
name = "logging_macro"
version = "0.9.5"
authors = ["Noah Santschi-Cooney <noah@santschi-cooney.ch>"]
edition = "2021"
[lib]
proc-macro = true
[dependencies]
quote = "1.0"
syn = { version = "1.0", features = [ "full" ] }

View file

@ -0,0 +1,24 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, parse_quote, ItemFn};
#[proc_macro_attribute]
pub fn log_scope(_args: TokenStream, function: TokenStream) -> TokenStream {
let mut function = parse_macro_input!(function as ItemFn);
let function_name = function.sig.ident.to_string();
let stmts = function.block.stmts;
function.block = Box::new(parse_quote!({
use slog::{slog_o, FnValue, Level};
use std::thread::current;
let _guard = logging::set_logger_with_level(Level::Trace);
slog_scope::scope(&slog_scope::logger().new(slog_o!("test_name" => #function_name, "thread_num" => FnValue(|_| format!("{:?}", current().id())))), || {
#(#stmts)*
});
}));
TokenStream::from(quote!(#function))
}