@@ -9,49 +9,51 @@ macro_rules! cubeb_log_internal {
9
9
#[ allow( unused_unsafe) ]
10
10
unsafe {
11
11
if $level <= $crate:: ffi:: g_cubeb_log_level. into( ) {
12
- if let Some ( log_callback) = $crate:: ffi:: g_cubeb_log_callback {
13
- let cstr = :: std:: ffi:: CString :: new( concat!( "%s:%d: " , $msg, "\n " ) ) . unwrap( ) ;
14
- log_callback( cstr. as_ptr( ) , file!( ) , line!( ) ) ;
15
- }
12
+ cubeb_log_internal!( __INTERNAL__ $msg) ;
16
13
}
17
14
}
18
15
} ;
19
- ( $level: expr, $fmt: expr, $( $arg: tt ) +) => {
16
+ ( $level: expr, $fmt: expr, $( $arg: expr ) , +) => {
20
17
#[ allow( unused_unsafe) ]
21
18
unsafe {
22
19
if $level <= $crate:: ffi:: g_cubeb_log_level. into( ) {
23
- if let Some ( log_callback) = $crate:: ffi:: g_cubeb_log_callback {
24
- let cstr = :: std:: ffi:: CString :: new( concat!( "%s:%d: " , $fmt, "\n " ) ) . unwrap( ) ;
25
- log_callback( cstr. as_ptr( ) , file!( ) , line!( ) , $( $arg) +) ;
26
- }
20
+ cubeb_log_internal!( __INTERNAL__ format!( $fmt, $( $arg) ,* ) ) ;
27
21
}
28
22
}
23
+ } ;
24
+ ( __INTERNAL__ $msg: expr) => {
25
+ if let Some ( log_callback) = $crate:: ffi:: g_cubeb_log_callback {
26
+ let cstr = :: std:: ffi:: CString :: new( format!( "{}:{}: {}\n " , file!( ) , line!( ) , $msg) ) . unwrap( ) ;
27
+ log_callback( cstr. as_ptr( ) ) ;
28
+ }
29
29
}
30
30
}
31
31
32
32
#[ macro_export]
33
33
macro_rules! cubeb_logv {
34
34
( $msg: expr) => ( cubeb_log_internal!( $crate:: LogLevel :: Verbose , $msg) ) ;
35
- ( $fmt: expr, $( $arg: tt ) +) => ( cubeb_log_internal!( $crate:: LogLevel :: Verbose , $fmt, $( $arg) * ) ) ;
35
+ ( $fmt: expr, $( $arg: expr ) , +) => ( cubeb_log_internal!( $crate:: LogLevel :: Verbose , $fmt, $( $arg) , * ) ) ;
36
36
}
37
37
38
38
#[ macro_export]
39
39
macro_rules! cubeb_log {
40
40
( $msg: expr) => ( cubeb_log_internal!( $crate:: LogLevel :: Normal , $msg) ) ;
41
- ( $fmt: expr, $( $arg: tt ) +) => ( cubeb_log_internal!( $crate:: LogLevel :: Normal , $fmt, $( $arg) * ) ) ;
41
+ ( $fmt: expr, $( $arg: expr ) , +) => ( cubeb_log_internal!( $crate:: LogLevel :: Normal , $fmt, $( $arg) , * ) ) ;
42
42
}
43
43
44
44
#[ cfg( test) ]
45
45
mod tests {
46
46
#[ test]
47
47
fn test_normal_logging ( ) {
48
48
cubeb_log ! ( "This is log at normal level" ) ;
49
- cubeb_log ! ( "Formatted log %d" , 1 ) ;
49
+ cubeb_log ! ( "{} Formatted log" , 1 ) ;
50
+ cubeb_log ! ( "{} Formatted {} log {}" , 1 , 2 , 3 ) ;
50
51
}
51
52
52
53
#[ test]
53
54
fn test_verbose_logging ( ) {
54
55
cubeb_logv ! ( "This is a log at verbose level" ) ;
55
- cubeb_logv ! ( "Formatted log %d" , 1 ) ;
56
+ cubeb_logv ! ( "{} Formatted log" , 1 ) ;
57
+ cubeb_logv ! ( "{} Formatted {} log {}" , 1 , 2 , 3 ) ;
56
58
}
57
59
}
0 commit comments