77
88use crate :: chain:: { ChainSource , DEFAULT_ESPLORA_SERVER_URL } ;
99use crate :: config:: {
10- default_user_config, Config , EsploraSyncConfig , DEFAULT_LOG_FILE_PATH , DEFAULT_LOG_LEVEL ,
11- DEFAULT_STORAGE_DIR_PATH , WALLET_KEYS_SEED_LEN ,
10+ default_user_config, Config , EsploraSyncConfig , DEFAULT_LOG_FILENAME , DEFAULT_LOG_LEVEL ,
11+ WALLET_KEYS_SEED_LEN ,
1212} ;
1313
1414use crate :: connection:: ConnectionManager ;
@@ -111,18 +111,7 @@ impl Default for LiquiditySourceConfig {
111111
112112#[ derive( Clone ) ]
113113enum LogWriterConfig {
114- File {
115- /// The log file path.
116- ///
117- /// This specifies the log file path if a destination other than the storage
118- /// directory, i.e. [`Config::storage_dir_path`], is preferred. If unconfigured,
119- /// defaults to [`DEFAULT_LOG_FILE_PATH`] in default storage directory.
120- log_file_path : Option < String > ,
121- /// This specifies the log level.
122- ///
123- /// If unconfigured, defaults to `Debug`.
124- log_level : Option < LogLevel > ,
125- } ,
114+ File { log_file_path : Option < String > , log_level : Option < LogLevel > } ,
126115 Log ( LogLevel ) ,
127116 Custom ( Arc < dyn LogWriter > ) ,
128117}
@@ -143,15 +132,6 @@ impl std::fmt::Debug for LogWriterConfig {
143132 }
144133}
145134
146- impl Default for LogWriterConfig {
147- fn default ( ) -> Self {
148- Self :: File {
149- log_file_path : Some ( DEFAULT_LOG_FILE_PATH . to_string ( ) ) ,
150- log_level : Some ( DEFAULT_LOG_LEVEL ) ,
151- }
152- }
153- }
154-
155135/// An error encountered during building a [`Node`].
156136///
157137/// [`Node`]: crate::Node
@@ -349,9 +329,11 @@ impl NodeBuilder {
349329
350330 /// Configures the [`Node`] instance to write logs to the filesystem.
351331 ///
352- /// The `log_file_path` defaults to the [`DEFAULT_LOG_FILE_PATH`] in the default
353- /// storage directory if set to None.
354- /// The `log_level` defaults to [`DEFAULT_LOG_LEVEL`] if set to None.
332+ /// The `log_file_path` defaults to [`DEFAULT_LOG_FILENAME`] in the configured
333+ /// [`Config::storage_dir_path`] if set to `None`.
334+ /// The `log_level` defaults to [`DEFAULT_LOG_LEVEL`] if set to `None`.
335+ ///
336+ /// [`DEFAULT_LOG_FILENAME`]: crate::config::DEFAULT_LOG_FILENAME
355337 pub fn set_filesystem_logger (
356338 & mut self , log_file_path : Option < String > , log_level : Option < LogLevel > ,
357339 ) -> & mut Self {
@@ -674,9 +656,11 @@ impl ArcedNodeBuilder {
674656
675657 /// Configures the [`Node`] instance to write logs to the filesystem.
676658 ///
677- /// The `log_file_path` defaults to the [`DEFAULT_LOG_FILENAME`] in the default
678- /// storage directory if set to None.
679- /// The `log_level` defaults to [`DEFAULT_LOG_LEVEL`] if set to None.
659+ /// The `log_file_path` defaults to [`DEFAULT_LOG_FILENAME`] in the configured
660+ /// [`Config::storage_dir_path`] if set to `None`.
661+ /// The `log_level` defaults to [`DEFAULT_LOG_LEVEL`] if set to `None`.
662+ ///
663+ /// [`DEFAULT_LOG_FILENAME`]: crate::config::DEFAULT_LOG_FILENAME
680664 pub fn set_filesystem_logger (
681665 & self , log_file_path : Option < String > , log_level : Option < LogLevel > ,
682666 ) {
@@ -1317,34 +1301,31 @@ fn build_with_store_internal(
13171301}
13181302
13191303/// Sets up the node logger.
1320- ///
1321- /// If `log_writer_conf` is set to None, uses [`LogWriterConfig::default()`].
1322- /// The `node_conf` is provided to access the configured storage directory.
13231304fn setup_logger (
1324- log_writer_conf : & Option < LogWriterConfig > , node_conf : & Config ,
1305+ log_writer_config : & Option < LogWriterConfig > , config : & Config ,
13251306) -> Result < Arc < Logger > , BuildError > {
1326- let is_default = log_writer_conf. is_none ( ) ;
1327- let default_lw_config = LogWriterConfig :: default ( ) ;
1328- let log_writer_config =
1329- if let Some ( conf) = log_writer_conf { conf } else { & default_lw_config } ;
1330-
13311307 let logger = match log_writer_config {
1332- LogWriterConfig :: File { log_file_path, log_level } => {
1333- let fp = DEFAULT_LOG_FILE_PATH
1334- . replace ( DEFAULT_STORAGE_DIR_PATH , & node_conf. storage_dir_path ) ;
1335- let log_file_path =
1336- if is_default { & fp } else { log_file_path. as_ref ( ) . map ( |p| p) . unwrap_or ( & fp) } ;
1337-
1338- let log_level = log_level. unwrap_or ( DEFAULT_LOG_LEVEL ) ;
1308+ Some ( LogWriterConfig :: File { log_file_path, log_level } ) => {
1309+ let log_file_path = log_file_path
1310+ . clone ( )
1311+ . unwrap_or_else ( || format ! ( "{}/{}" , config. storage_dir_path, DEFAULT_LOG_FILENAME ) ) ;
1312+ let log_level = log_level. unwrap_or_else ( || DEFAULT_LOG_LEVEL ) ;
13391313
13401314 Logger :: new_fs_writer ( log_file_path, log_level)
13411315 . map_err ( |_| BuildError :: LoggerSetupFailed ) ?
13421316 } ,
1343- LogWriterConfig :: Log ( log_level) => Logger :: new_log_facade ( * log_level) ,
1317+ Some ( LogWriterConfig :: Log ( log_level) ) => Logger :: new_log_facade ( * log_level) ,
13441318
1345- LogWriterConfig :: Custom ( custom_log_writer) => {
1319+ Some ( LogWriterConfig :: Custom ( custom_log_writer) ) => {
13461320 Logger :: new_custom_writer ( Arc :: clone ( & custom_log_writer) )
13471321 } ,
1322+ None => {
1323+ // Default to use `FileWriter`
1324+ let log_file_path = format ! ( "{}/{}" , config. storage_dir_path, DEFAULT_LOG_FILENAME ) ;
1325+ let log_level = DEFAULT_LOG_LEVEL ;
1326+ Logger :: new_fs_writer ( log_file_path, log_level)
1327+ . map_err ( |_| BuildError :: LoggerSetupFailed ) ?
1328+ } ,
13481329 } ;
13491330
13501331 Ok ( Arc :: new ( logger) )
0 commit comments