@@ -107,7 +107,8 @@ pub struct Record<$($args)?> {
107107 /// generated.
108108 pub peer_id: Option <PublicKey >,
109109 /// The channel id of the channel pertaining to the logged record. May be a temporary id before
110- /// the channel has been funded.
110+ /// the channel has been funded. Since channel_id is not repeated in the message body,
111+ /// include it in the log output so entries remain clear.
111112 pub channel_id: Option <ChannelId >,
112113 #[ cfg( not( c_bindings) ) ]
113114 /// The message body.
@@ -156,8 +157,10 @@ impl<$($args)?> Record<$($args)?> {
156157
157158impl <$( $args) ?> Display for Record <$( $args) ?> {
158159 fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
160+ let chan_id = self . channel_id. map( |id| format!( "{}" , id) ) ;
161+ let chan_str = chan_id. as_deref( ) . and_then( |s| s. get( ..6 ) ) . unwrap_or( "" ) ;
159162 let context = format!( "{:<5} [{}:{}]" , self . level, self . module_path, self . line) ;
160- write!( f, "{:<48} {} " , context, self . args)
163+ write!( f, "{:<48} {:<6} {} " , context, chan_str , self . args)
161164 }
162165}
163166} }
@@ -166,9 +169,11 @@ impl_record!('a, );
166169#[ cfg( c_bindings) ]
167170impl_record ! ( , ' a) ;
168171
169- /// A trait encapsulating the operations required of a logger.
172+ /// A trait encapsulating the operations required of a logger. Keep in mind that log messages might not be entirely
173+ /// self-explanatory and may need accompanying context fields to be fully understood.
170174pub trait Logger {
171- /// Logs the [`Record`].
175+ /// Logs the [`Record`]. Since the record's [`Record::channel_id`] is not embedded in the message body, log
176+ /// implementations should print it alongside the message to keep entries clear.
172177 fn log ( & self , record : Record ) ;
173178}
174179
0 commit comments