Skip to content

Commit

Permalink
feat: revert to short filename for TextLayout (#57)
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Aug 21, 2024
1 parent 406b9d6 commit fbac1b9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::borrow::Cow;
use std::fmt::Arguments;

use colored::Color;
Expand Down Expand Up @@ -153,7 +154,7 @@ impl TextLayout {
ColoredString::from(record.level().to_string()).color(color)
};
let module = record.module_path().unwrap_or_default();
let file = record.file().unwrap_or_default();
let file = filename(record);
let line = record.line().unwrap_or_default();
let message = record.args();
let kvs = KvDisplay::new(record.key_values());
Expand All @@ -169,3 +170,14 @@ impl From<TextLayout> for Layout {
Layout::Text(layout)
}
}

// obtain filename only from record's full file path
// reason: the module is already logged + full file path is noisy for text layout
fn filename<'a>(record: &'a log::Record<'a>) -> Cow<'a, str> {
record
.file()
.map(std::path::Path::new)
.and_then(std::path::Path::file_name)
.map(std::ffi::OsStr::to_string_lossy)
.unwrap_or_default()
}

0 comments on commit fbac1b9

Please sign in to comment.