From 52035ef672e1944ac8f1f2c8e28a9eb4e2d558d4 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Tue, 27 Oct 2020 11:29:21 +0100 Subject: [PATCH] Add tracing logger --- extractor/src/extractor.rs | 35 +++++++++++++++++++++++------------ extractor/src/main.rs | 7 +++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/extractor/src/extractor.rs b/extractor/src/extractor.rs index b724ce384a2..c57179c22b7 100644 --- a/extractor/src/extractor.rs +++ b/extractor/src/extractor.rs @@ -4,6 +4,7 @@ use std::collections::BTreeMap as Map; use std::collections::BTreeSet as Set; use std::fmt; use std::path::Path; +use tracing::{error, info, span, Level}; use tree_sitter::{Language, Node, Parser, Tree}; pub struct Extractor { @@ -19,6 +20,16 @@ pub fn create(language: Language, schema: Vec) -> Extractor { } impl Extractor { pub fn extract<'a>(&'a mut self, path: &Path) -> std::io::Result { + let span = span!( + Level::TRACE, + "extract", + file = &path.display().to_string()[..] + ); + + let _enter = span.enter(); + + info!("extracting: {}", path.display()); + let source = std::fs::read(&path)?; let tree = &self .parser @@ -88,16 +99,16 @@ struct Visitor<'a> { impl Visitor<'_> { fn enter_node(&mut self, node: Node) -> bool { if node.is_error() { - println!( - "error: {}:{}: parse error", + error!( + "{}:{}: parse error", &self.path, node.start_position().row, ); return false; } if node.is_missing() { - println!( - "error: {}:{}: parse error: expecting '{}'", + error!( + "{}:{}: parse expecting '{}'", &self.path, node.start_position().row, node.kind() @@ -151,8 +162,8 @@ impl Visitor<'_> { )) }; } else { - println!( - "error: {}:{}: unknown table type: '{}'", + error!( + "{}:{}: unknown table type: '{}'", &self.path, node.start_position().row, node.kind() @@ -176,8 +187,8 @@ impl Visitor<'_> { if self.type_matches(&child_type, &field.types) { values.push(child_id); } else if field.name.is_some() { - println!( - "error: {}:{}: type mismatch for field {}::{} with type {:?} != {:?}", + error!( + "{}:{}: type mismatch for field {}::{} with type {:?} != {:?}", &self.path, node.start_position().row, node.kind(), @@ -188,8 +199,8 @@ impl Visitor<'_> { } } else { if child_field.is_some() || child_type.named { - println!( - "error: {}:{}: value for unknown field: {}::{} and type {:?}", + error!( + "{}:{}: value for unknown field: {}::{} and type {:?}", &self.path, node.start_position().row, node.kind(), @@ -209,8 +220,8 @@ impl Visitor<'_> { args.push(Arg::Label(*child_ids.first().unwrap())); } else { is_valid = false; - println!( - "error: {}:{}: {} for field: {}::{}", + error!( + "{}:{}: {} for field: {}::{}", &self.path, node.start_position().row, if child_ids.is_empty() { diff --git a/extractor/src/main.rs b/extractor/src/main.rs index 2200ab366b5..582d56852cf 100644 --- a/extractor/src/main.rs +++ b/extractor/src/main.rs @@ -12,6 +12,13 @@ fn main() -> std::io::Result<()> { fn tree_sitter_ruby() -> Language; } + tracing_subscriber::fmt() + .with_target(false) + .without_time() + .with_level(true) + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init(); + let matches = clap::App::new("Ruby extractor") .version("1.0") .author("GitHub")