Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: revert to short filename for TextLayout #57

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}