mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Tree-sitter: Add set_tracing_level to shared extractor module
This commit is contained in:
@@ -9,6 +9,7 @@ flate2 = "1.0"
|
||||
globset = "0.4"
|
||||
tree-sitter = ">= 0.22.6"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
|
||||
rayon = "1.5.0"
|
||||
regex = "1.7.1"
|
||||
encoding = "0.2"
|
||||
|
||||
@@ -4,12 +4,44 @@ use crate::node_types::{self, EntryKind, Field, NodeTypeMap, Storage, TypeName};
|
||||
use crate::trap;
|
||||
use std::collections::BTreeMap as Map;
|
||||
use std::collections::BTreeSet as Set;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
use tree_sitter::{Language, Node, Parser, Range, Tree};
|
||||
|
||||
pub mod simple;
|
||||
|
||||
/// Sets the tracing level based on the environment variables
|
||||
/// `RUST_LOG` and `CODEQL_VERBOSITY` (prioritized in that order),
|
||||
/// falling back to `warn` if neither is set.
|
||||
pub fn set_tracing_level(language: &str) -> () {
|
||||
tracing_subscriber::fmt()
|
||||
.with_target(false)
|
||||
.without_time()
|
||||
.with_level(true)
|
||||
.with_env_filter(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(
|
||||
|_| -> tracing_subscriber::EnvFilter {
|
||||
let verbosity = env::var("CODEQL_VERBOSITY")
|
||||
.map(|v| match v.to_lowercase().as_str() {
|
||||
"off" | "errors" => "error",
|
||||
"warnings" => "warn",
|
||||
"info" | "progress" => "info",
|
||||
"debug" | "progress+" => "debug",
|
||||
"trace" | "progress++" | "progress+++" => "trace",
|
||||
_ => "warn",
|
||||
})
|
||||
.unwrap_or_else(|_| "warn");
|
||||
tracing_subscriber::EnvFilter::new(format!(
|
||||
"{}_extractor={}",
|
||||
language, verbosity
|
||||
))
|
||||
},
|
||||
),
|
||||
)
|
||||
.init();
|
||||
}
|
||||
|
||||
pub fn populate_file(writer: &mut trap::Writer, absolute_path: &Path) -> trap::Label {
|
||||
let (file_label, fresh) = writer.global_id(&trap::full_id_for_file(
|
||||
&file_paths::normalize_path(absolute_path),
|
||||
|
||||
Reference in New Issue
Block a user