@@ -39,6 +39,7 @@ pub struct Record<'a> {
3939 pub level : log:: Level ,
4040 pub message : & ' a std:: fmt:: Arguments < ' a > ,
4141 pub module_path : Option < & ' a str > ,
42+ pub line : Option < u32 > ,
4243}
4344
4445pub fn init_output_stdout ( ) {
@@ -105,7 +106,11 @@ static LEVEL_ANSI_COLORS: [&str; 6] = [
105106] ;
106107
107108// PERF: batching
108- pub fn submit ( record : Record ) {
109+ pub fn submit ( mut record : Record ) {
110+ if record. module_path . is_none_or ( |p| !p. ends_with ( ".rs" ) ) {
111+ // Only render line numbers for actual rust files emitted by `log_err` and friends
112+ record. line . take ( ) ;
113+ }
109114 if ENABLED_SINKS_STDOUT . load ( Ordering :: Acquire ) {
110115 let mut stdout = std:: io:: stdout ( ) . lock ( ) ;
111116 _ = writeln ! (
@@ -117,6 +122,7 @@ pub fn submit(record: Record) {
117122 SourceFmt {
118123 scope: record. scope,
119124 module_path: record. module_path,
125+ line: record. line,
120126 ansi: true ,
121127 } ,
122128 record. message
@@ -132,6 +138,7 @@ pub fn submit(record: Record) {
132138 SourceFmt {
133139 scope: record. scope,
134140 module_path: record. module_path,
141+ line: record. line,
135142 ansi: true ,
136143 } ,
137144 record. message
@@ -167,6 +174,7 @@ pub fn submit(record: Record) {
167174 SourceFmt {
168175 scope: record. scope,
169176 module_path: record. module_path,
177+ line: record. line,
170178 ansi: false ,
171179 } ,
172180 record. message
@@ -202,6 +210,7 @@ pub fn flush() {
202210struct SourceFmt < ' a > {
203211 scope : Scope ,
204212 module_path : Option < & ' a str > ,
213+ line : Option < u32 > ,
205214 ansi : bool ,
206215}
207216
@@ -225,6 +234,10 @@ impl std::fmt::Display for SourceFmt<'_> {
225234 f. write_str ( subscope) ?;
226235 }
227236 }
237+ if let Some ( line) = self . line {
238+ f. write_char ( ':' ) ?;
239+ line. fmt ( f) ?;
240+ }
228241 if self . ansi {
229242 f. write_str ( ANSI_RESET ) ?;
230243 }
0 commit comments