@@ -106,18 +106,18 @@ pub trait LogWriter: Send + Sync {
106106/// Defines a writer for [`Logger`].
107107pub ( crate ) enum Writer {
108108 /// Writes logs to the file system.
109- FileWriter { file_path : String , level : LogLevel } ,
109+ FileWriter { file_path : String , max_log_level : LogLevel } ,
110110 /// Forwards logs to the `log` facade.
111- LogFacadeWriter { level : LogLevel } ,
111+ LogFacadeWriter { max_log_level : LogLevel } ,
112112 /// Forwards logs to a custom writer.
113113 CustomWriter ( Arc < dyn LogWriter > ) ,
114114}
115115
116116impl LogWriter for Writer {
117117 fn log ( & self , record : LogRecord ) {
118118 match self {
119- Writer :: FileWriter { file_path, level } => {
120- if record. level < * level {
119+ Writer :: FileWriter { file_path, max_log_level } => {
120+ if record. level < * max_log_level {
121121 return ;
122122 }
123123
@@ -138,7 +138,10 @@ impl LogWriter for Writer {
138138 . write_all ( log. as_bytes ( ) )
139139 . expect ( "Failed to write to log file" )
140140 } ,
141- Writer :: LogFacadeWriter { level } => {
141+ Writer :: LogFacadeWriter { max_log_level } => {
142+ if record. level < * max_log_level {
143+ return ;
144+ }
142145 macro_rules! log_with_level {
143146 ( $log_level: expr, $( $args: tt) * ) => {
144147 match $log_level {
@@ -152,7 +155,7 @@ impl LogWriter for Writer {
152155 }
153156
154157 log_with_level ! (
155- level ,
158+ max_log_level ,
156159 "{} {:<5} [{}:{}] {}" ,
157160 Utc :: now( ) . format( "%Y-%m-%d %H:%M:%S" ) ,
158161 record. level,
@@ -174,7 +177,7 @@ pub(crate) struct Logger {
174177impl Logger {
175178 /// Creates a new logger with a filesystem writer. The parameters to this function
176179 /// are the path to the log file, and the log level.
177- pub fn new_fs_writer ( file_path : String , level : LogLevel ) -> Result < Self , ( ) > {
180+ pub fn new_fs_writer ( file_path : String , max_log_level : LogLevel ) -> Result < Self , ( ) > {
178181 if let Some ( parent_dir) = Path :: new ( & file_path) . parent ( ) {
179182 fs:: create_dir_all ( parent_dir)
180183 . map_err ( |e| eprintln ! ( "ERROR: Failed to create log parent directory: {}" , e) ) ?;
@@ -187,11 +190,11 @@ impl Logger {
187190 . map_err ( |e| eprintln ! ( "ERROR: Failed to open log file: {}" , e) ) ?;
188191 }
189192
190- Ok ( Self { writer : Writer :: FileWriter { file_path, level } } )
193+ Ok ( Self { writer : Writer :: FileWriter { file_path, max_log_level } } )
191194 }
192195
193- pub fn new_log_facade ( level : LogLevel ) -> Self {
194- Self { writer : Writer :: LogFacadeWriter { level } }
196+ pub fn new_log_facade ( max_log_level : LogLevel ) -> Self {
197+ Self { writer : Writer :: LogFacadeWriter { max_log_level } }
195198 }
196199
197200 pub fn new_custom_writer ( log_writer : Arc < dyn LogWriter > ) -> Self {
@@ -202,14 +205,14 @@ impl Logger {
202205impl LdkLogger for Logger {
203206 fn log ( & self , record : LdkRecord ) {
204207 match & self . writer {
205- Writer :: FileWriter { file_path : _, level } => {
206- if record. level < * level {
208+ Writer :: FileWriter { file_path : _, max_log_level } => {
209+ if record. level < * max_log_level {
207210 return ;
208211 }
209212 self . writer . log ( record. into ( ) ) ;
210213 } ,
211- Writer :: LogFacadeWriter { level } => {
212- if record. level < * level {
214+ Writer :: LogFacadeWriter { max_log_level } => {
215+ if record. level < * max_log_level {
213216 return ;
214217 }
215218 self . writer . log ( record. into ( ) ) ;
0 commit comments