@@ -2,6 +2,7 @@ use crate::diagnostics;
22use crate :: file_paths;
33use crate :: node_types:: { self , EntryKind , Field , NodeTypeMap , Storage , TypeName } ;
44use crate :: trap;
5+ use serde:: { Deserialize , Serialize } ;
56use std:: collections:: BTreeMap as Map ;
67use std:: collections:: BTreeSet as Set ;
78use std:: env;
@@ -18,13 +19,33 @@ use tree_sitter::{Language, Node, Parser, Range, Tree};
1819
1920pub mod simple;
2021
22+ #[ derive( Clone , Copy , PartialEq , Eq , Debug , Serialize , Deserialize ) ]
23+ pub enum Color {
24+ Yes ,
25+ No ,
26+ }
27+
28+ impl Color {
29+ pub fn from ( condition : bool ) -> Self {
30+ if condition {
31+ Color :: Yes
32+ } else {
33+ Color :: No
34+ }
35+ }
36+ }
37+
2138/// Sets the tracing level based on the environment variables
2239/// `RUST_LOG` and `CODEQL_VERBOSITY` (prioritized in that order),
2340/// falling back to `warn` if neither is set.
2441pub fn set_tracing_level ( language : & str ) {
2542 let verbosity = env:: var ( "CODEQL_VERBOSITY" ) . ok ( ) ;
2643 tracing_subscriber:: registry ( )
27- . with ( default_subscriber_with_level ( language, & verbosity) )
44+ . with ( default_subscriber_with_level (
45+ language,
46+ & verbosity,
47+ Color :: Yes ,
48+ ) )
2849 . init ( ) ;
2950}
3051
@@ -33,6 +54,7 @@ pub fn set_tracing_level(language: &str) {
3354pub fn default_subscriber_with_level (
3455 language : & str ,
3556 verbosity : & Option < String > ,
57+ color : Color ,
3658) -> Filtered <
3759 tracing_subscriber:: fmt:: Layer <
3860 tracing_subscriber:: Registry ,
@@ -46,6 +68,7 @@ pub fn default_subscriber_with_level(
4668 . with_target ( false )
4769 . without_time ( )
4870 . with_level ( true )
71+ . with_ansi ( color == Color :: Yes )
4972 . with_filter (
5073 tracing_subscriber:: EnvFilter :: try_from_default_env ( ) . unwrap_or_else (
5174 |_| -> tracing_subscriber:: EnvFilter {
0 commit comments