77
88//! Objects for configuring the node.
99
10- use crate :: logger:: LdkNodeLogger ;
10+ use crate :: logger:: LogWriter ;
1111use crate :: payment:: SendingParameters ;
1212
1313use lightning:: ln:: msgs:: SocketAddress ;
1414use lightning:: routing:: gossip:: NodeAlias ;
1515use lightning:: util:: config:: ChannelConfig as LdkChannelConfig ;
1616use lightning:: util:: config:: MaxDustHTLCExposure as LdkMaxDustHTLCExposure ;
1717use lightning:: util:: config:: UserConfig ;
18- use lightning:: util:: logger:: Level as LogLevel ;
18+ use lightning:: util:: logger:: Level ;
1919
2020use bitcoin:: secp256k1:: PublicKey ;
2121use bitcoin:: Network ;
2222
23+ use std:: sync:: Arc ;
2324use std:: time:: Duration ;
2425
2526// Config defaults
2627const DEFAULT_STORAGE_DIR_PATH : & str = "/tmp/ldk_node" ;
28+ const DEFAULT_LOG_FILE_PATH : & str = "/tmp/ldk_node/ldk_node.log" ;
2729const DEFAULT_NETWORK : Network = Network :: Bitcoin ;
2830const DEFAULT_BDK_WALLET_SYNC_INTERVAL_SECS : u64 = 80 ;
2931const DEFAULT_LDK_WALLET_SYNC_INTERVAL_SECS : u64 = 30 ;
3032const DEFAULT_FEE_RATE_CACHE_UPDATE_INTERVAL_SECS : u64 = 60 * 10 ;
3133const DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER : u64 = 3 ;
32- const DEFAULT_LOG_LEVEL : LogLevel = LogLevel :: Debug ;
34+ const DEFAULT_LOG_LEVEL : Level = Level :: Debug ;
3335const DEFAULT_ANCHOR_PER_CHANNEL_RESERVE_SATS : u64 = 25_000 ;
3436
3537// The 'stop gap' parameter used by BDK's wallet sync. This seems to configure the threshold
@@ -104,9 +106,8 @@ pub(crate) const WALLET_KEYS_SEED_LEN: usize = 64;
104106pub struct Config {
105107 /// The path where the underlying LDK and BDK persist their data.
106108 pub storage_dir_path : String ,
107- /// In the default configuration logs can be found in the [`DEFAULT_STORAGE_DIR_PATH`] subdirectory in
108- /// [`Config::storage_dir_path`], and the log level is set to [`DEFAULT_LOG_LEVEL`].
109- pub logging_config : LoggingConfig ,
109+ /// The configuration options for the logger.
110+ pub logger_config : LoggerConfig ,
110111 /// The used Bitcoin network.
111112 pub network : Network ,
112113 /// The addresses on which the node will listen for incoming connections.
@@ -163,7 +164,7 @@ impl Default for Config {
163164 fn default ( ) -> Self {
164165 Self {
165166 storage_dir_path : DEFAULT_STORAGE_DIR_PATH . to_string ( ) ,
166- logging_config : LoggingConfig :: default ( ) ,
167+ logger_config : LoggerConfig :: default ( ) ,
167168 network : DEFAULT_NETWORK ,
168169 listening_addresses : None ,
169170 trusted_peers_0conf : Vec :: new ( ) ,
@@ -175,34 +176,109 @@ impl Default for Config {
175176 }
176177}
177178
178- /// Configuration options for logging .
179+ /// Logger configuration .
179180#[ derive( Debug , Clone ) ]
180- pub enum LoggingConfig {
181- /// An opinionated filesystem logger.
182- ///
183- /// This logger will always write at `{log_dir}/ldk_node_latest.log`, which is a symlink to the
184- /// most recent log file, which is created and timestamped at initialization.
185- Filesystem {
186- /// The absolute path where logs are stored.
187- log_file_path : String ,
188- /// The level at which we log messages.
189- ///
190- /// Any messages below this level will be excluded from the logs.
191- log_level : LogLevel ,
192- } ,
193- /// A custom logger.
194- Custom ( std:: sync:: Arc < LdkNodeLogger > ) ,
181+ pub struct LoggerConfig {
182+ /// Writer configuration.
183+ pub writer : WriterConfig ,
184+ /// Formatter configuration.
185+ pub formatter : FormatterConfig ,
186+ }
187+
188+ impl Default for LoggerConfig {
189+ fn default ( ) -> Self {
190+ Self { writer : WriterConfig :: default ( ) , formatter : FormatterConfig :: default ( ) }
191+ }
192+ }
193+
194+ /// Logger formatter configuration.
195+ #[ derive( Debug , Clone ) ]
196+ pub struct FormatterConfig {
197+ /// Specifies if timestamps should be included in the log messages.
198+ pub include_timestamp : bool ,
199+ /// Specifies timestamp format , e.g., "%Y-%m-%d %H:%M:%S".
200+ pub timestamp_format : Option < String > ,
201+ /// Specifies if log levels should be included in the log messages.
202+ pub include_level : bool ,
203+ /// Specifies the template for log message format, e.g., "{timestamp} [{level}] {message}".
204+ pub message_template : Option < String > ,
195205}
196206
197- impl Default for LoggingConfig {
207+ impl Default for FormatterConfig {
198208 fn default ( ) -> Self {
199- Self :: Filesystem {
200- log_file_path : format ! ( "{}/{}" , DEFAULT_STORAGE_DIR_PATH , "ldk_node.log" ) ,
201- log_level : DEFAULT_LOG_LEVEL ,
209+ Self {
210+ include_timestamp : true ,
211+ timestamp_format : Some ( "%Y-%m-%d %H:%M:%S" . to_string ( ) ) ,
212+ include_level : true ,
213+ message_template : Some (
214+ "{timestamp} {level} [{module_path}:{line}] {message}\n " . to_string ( ) ,
215+ ) ,
202216 }
203217 }
204218}
205219
220+ /// Logger writer configuration.
221+ #[ derive( Debug , Clone ) ]
222+ pub struct WriterConfig {
223+ /// Writer type for the logger.
224+ pub writer_type : WriterType ,
225+ }
226+
227+ impl Default for WriterConfig {
228+ fn default ( ) -> Self {
229+ WriterConfig {
230+ writer_type : WriterType :: File ( FileWriterConfig :: new (
231+ DEFAULT_LOG_FILE_PATH ,
232+ DEFAULT_LOG_LEVEL ,
233+ ) ) ,
234+ }
235+ }
236+ }
237+
238+ /// Log writer configuration type.
239+ #[ derive( Debug , Clone ) ]
240+ pub enum WriterType {
241+ /// Wraps configuration options for logging to the filesystem.
242+ File ( FileWriterConfig ) ,
243+ /// Wraps configuration options for relaying logs to [`log`].
244+ LogRelay ( LogRelayWriterConfig ) ,
245+ /// Wraps configuration options for relaying logs to a custom logger.
246+ Custom ( CustomWriterConfig ) ,
247+ }
248+
249+ /// Configuration for writing to the filesystem.
250+ #[ derive( Debug , Clone ) ]
251+ pub struct FileWriterConfig {
252+ /// Specifies the file path for the logs.
253+ pub log_file_path : String ,
254+ /// Specifies the log level.
255+ pub level : Level ,
256+ }
257+
258+ impl FileWriterConfig {
259+ /// Creates a new configuration given the path to the log file
260+ /// and the log level.
261+ pub fn new ( log_file_path : & str , level : Level ) -> Self {
262+ Self { log_file_path : log_file_path. to_string ( ) , level }
263+ }
264+ }
265+
266+ /// Configuration options for [`log`]'s writer.
267+ #[ derive( Debug , Clone ) ]
268+ pub struct LogRelayWriterConfig {
269+ /// Specifies the log level.
270+ pub level : Level ,
271+ }
272+
273+ /// Configuration options for a custom log writer.
274+ #[ derive( Debug , Clone ) ]
275+ pub struct CustomWriterConfig {
276+ /// Pointer to any custom log writer.
277+ pub inner : Arc < dyn LogWriter + Send + Sync > ,
278+ /// Specifies the log level.
279+ pub level : Level ,
280+ }
281+
206282/// Configuration options pertaining to 'Anchor' channels, i.e., channels for which the
207283/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
208284///
0 commit comments