55#[ macro_export]
66macro_rules! warning {
77 ( $name: expr) => {
8- println!( "{} {}" , ansi_term:: Colour :: Red . bold( ) . paint( "[!]" ) , $name) ;
8+ $crate:: print_log!(
9+ warn,
10+ "{} {}" ,
11+ ansi_term:: Colour :: Red . bold( ) . paint( "[!]" ) ,
12+ $name
13+ ) ;
914 } ;
1015 ( $name: expr, $greppable: expr, $accessible: expr) => {
1116 // if not greppable then print, otherwise no else statement so do not print.
1217 if !$greppable {
1318 if $accessible {
1419 // Don't print the ascii art
15- println! ( "{}" , $name) ;
20+ $crate :: print_log! ( warn , "{}" , $name) ;
1621 } else {
17- println!( "{} {}" , ansi_term:: Colour :: Red . bold( ) . paint( "[!]" ) , $name) ;
22+ $crate:: print_log!(
23+ warn,
24+ "{} {}" ,
25+ ansi_term:: Colour :: Red . bold( ) . paint( "[!]" ) ,
26+ $name
27+ ) ;
1828 }
1929 }
2030 } ;
@@ -23,16 +33,26 @@ macro_rules! warning {
2333#[ macro_export]
2434macro_rules! detail {
2535 ( $name: expr) => {
26- println!( "{} {}" , ansi_term:: Colour :: Blue . bold( ) . paint( "[~]" ) , $name) ;
36+ $crate:: print_log!(
37+ info,
38+ "{} {}" ,
39+ ansi_term:: Colour :: Blue . bold( ) . paint( "[~]" ) ,
40+ $name
41+ ) ;
2742 } ;
2843 ( $name: expr, $greppable: expr, $accessible: expr) => {
2944 // if not greppable then print, otherwise no else statement so do not print.
3045 if !$greppable {
3146 if $accessible {
3247 // Don't print the ascii art
33- println! ( "{}" , $name) ;
48+ $crate :: print_log! ( info , "{}" , $name) ;
3449 } else {
35- println!( "{} {}" , ansi_term:: Colour :: Blue . bold( ) . paint( "[~]" ) , $name) ;
50+ $crate:: print_log!(
51+ info,
52+ "{} {}" ,
53+ ansi_term:: Colour :: Blue . bold( ) . paint( "[~]" ) ,
54+ $name
55+ ) ;
3656 }
3757 }
3858 } ;
@@ -41,7 +61,8 @@ macro_rules! detail {
4161#[ macro_export]
4262macro_rules! output {
4363 ( $name: expr) => {
44- println!(
64+ $crate:: print_log!(
65+ info,
4566 "{} {}" ,
4667 RGansi_term :: Colour :: RGB ( 0 , 255 , 9 ) . bold( ) . paint( "[>]" ) ,
4768 $name
@@ -52,9 +73,10 @@ macro_rules! output {
5273 if !$greppable {
5374 if $accessible {
5475 // Don't print the ascii art
55- println! ( "{}" , $name) ;
76+ $crate :: print_log! ( info , "{}" , $name) ;
5677 } else {
57- println!(
78+ $crate:: print_log!(
79+ info,
5880 "{} {}" ,
5981 ansi_term:: Colour :: RGB ( 0 , 255 , 9 ) . bold( ) . paint( "[>]" ) ,
6082 $name
@@ -103,3 +125,23 @@ macro_rules! funny_opening {
103125 println!( "{}\n " , random_quote) ;
104126 } ;
105127}
128+
129+ /// Wrapper macro for printing/logging wraps println! and log::$level!
130+ /// 1. if rustscan::IS_CLI_MODE is true calls `println!`
131+ /// 2. if rustscan::IS_CLI_MODE is undefined or false `log::$level!` also sets IS_CLI_MODE
132+ /// to false if it was previously undefined.
133+ ///
134+ /// Library code should call this macro to print information that the binary
135+ /// is expected to print to stdout and library is expected to log at a
136+ /// level specified by parameter $level.
137+ #[ doc( hidden) ]
138+ #[ macro_export]
139+ macro_rules! print_log {
140+ ( $level: ident, $( $fmt_args: tt) * ) => {
141+ if * $crate:: IS_CLI_MODE . get_or_init( || false ) {
142+ println!( $( $fmt_args) * ) ;
143+ } else {
144+ log:: $level!( $( $fmt_args) * ) ;
145+ }
146+ }
147+ }
0 commit comments