@@ -4,12 +4,44 @@ use crate::node_types::{self, EntryKind, Field, NodeTypeMap, Storage, TypeName};
4
4
use crate :: trap;
5
5
use std:: collections:: BTreeMap as Map ;
6
6
use std:: collections:: BTreeSet as Set ;
7
+ use std:: env;
7
8
use std:: path:: Path ;
8
9
9
10
use tree_sitter:: { Language , Node , Parser , Range , Tree } ;
10
11
11
12
pub mod simple;
12
13
14
+ /// Sets the tracing level based on the environment variables
15
+ /// `RUST_LOG` and `CODEQL_VERBOSITY` (prioritized in that order),
16
+ /// falling back to `warn` if neither is set.
17
+ pub fn set_tracing_level ( language : & str ) -> ( ) {
18
+ tracing_subscriber:: fmt ( )
19
+ . with_target ( false )
20
+ . without_time ( )
21
+ . with_level ( true )
22
+ . with_env_filter (
23
+ tracing_subscriber:: EnvFilter :: try_from_default_env ( ) . unwrap_or_else (
24
+ |_| -> tracing_subscriber:: EnvFilter {
25
+ let verbosity = env:: var ( "CODEQL_VERBOSITY" )
26
+ . map ( |v| match v. to_lowercase ( ) . as_str ( ) {
27
+ "off" | "errors" => "error" ,
28
+ "warnings" => "warn" ,
29
+ "info" | "progress" => "info" ,
30
+ "debug" | "progress+" => "debug" ,
31
+ "trace" | "progress++" | "progress+++" => "trace" ,
32
+ _ => "warn" ,
33
+ } )
34
+ . unwrap_or_else ( |_| "warn" ) ;
35
+ tracing_subscriber:: EnvFilter :: new ( format ! (
36
+ "{}_extractor={}" ,
37
+ language, verbosity
38
+ ) )
39
+ } ,
40
+ ) ,
41
+ )
42
+ . init ( ) ;
43
+ }
44
+
13
45
pub fn populate_file ( writer : & mut trap:: Writer , absolute_path : & Path ) -> trap:: Label {
14
46
let ( file_label, fresh) = writer. global_id ( & trap:: full_id_for_file (
15
47
& file_paths:: normalize_path ( absolute_path) ,
0 commit comments