tweak format
This commit is contained in:
21
src/lib.rs
21
src/lib.rs
@@ -4,6 +4,11 @@ use log::*;
|
|||||||
use log::__private_api::enabled;
|
use log::__private_api::enabled;
|
||||||
//╶───╴Initializers╶─────────────────────────────────────────────────────────╴
|
//╶───╴Initializers╶─────────────────────────────────────────────────────────╴
|
||||||
|
|
||||||
|
const WIDTH_MODULE : usize = 14;
|
||||||
|
const WIDTH_FILE : usize = 8;
|
||||||
|
const WIDTH_TOTAL : usize = WIDTH_MODULE + WIDTH_FILE;
|
||||||
|
|
||||||
|
|
||||||
pub fn init() -> Result<(), SetLoggerError>{
|
pub fn init() -> Result<(), SetLoggerError>{
|
||||||
init_with_filter(LevelFilter::Info, |_|true)
|
init_with_filter(LevelFilter::Info, |_|true)
|
||||||
}
|
}
|
||||||
@@ -26,7 +31,7 @@ pub fn init_with_filter(
|
|||||||
//╶───╴PicoLogger╶───────────────────────────────────────────────────────────╴
|
//╶───╴PicoLogger╶───────────────────────────────────────────────────────────╴
|
||||||
|
|
||||||
pub struct PicoLogger<F: Fn(&Metadata) -> bool + Send + Sync> {
|
pub struct PicoLogger<F: Fn(&Metadata) -> bool + Send + Sync> {
|
||||||
filter: F
|
filter: F,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: Fn(&Metadata) -> bool + Send + Sync> Log for PicoLogger<F> {
|
impl<F: Fn(&Metadata) -> bool + Send + Sync> Log for PicoLogger<F> {
|
||||||
@@ -47,12 +52,12 @@ fn format(record: &Record) -> std::io::Result<()> {
|
|||||||
write!(buffer, "{GRAY}")?;
|
write!(buffer, "{GRAY}")?;
|
||||||
|
|
||||||
// module name
|
// module name
|
||||||
let mp = rtrunc(record.module_path().unwrap_or(""), 12);
|
let mp = rtrunc(record.module_path().unwrap_or(""), WIDTH_MODULE);
|
||||||
write!(buffer, "{mp:>12} ")?;
|
write!(buffer, "{mp:>w$} ", w=WIDTH_MODULE)?;
|
||||||
|
|
||||||
// file path
|
// file path
|
||||||
let fp = rtrunc(record.file().unwrap_or(""), 12);
|
let fp = rtrunc(record.file().unwrap_or(""), WIDTH_FILE);
|
||||||
write!(buffer, "{fp:>12}:{:<4}", record.line().unwrap_or(0))?;
|
write!(buffer, "{fp:>w$}:{:<4}", record.line().unwrap_or(0), w = WIDTH_FILE)?;
|
||||||
|
|
||||||
// write the record level
|
// write the record level
|
||||||
match record.level() {
|
match record.level() {
|
||||||
@@ -78,9 +83,9 @@ impl<'a> std::fmt::Write for LineSplicer<'a> {
|
|||||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||||
for (p, part) in s.split("\n").with_position() {
|
for (p, part) in s.split("\n").with_position() {
|
||||||
match p {
|
match p {
|
||||||
Position::First => write!(self.0, "\n {GRAY}╷{RESET} "),
|
Position::First => write!(self.0, "\n {:w$} {GRAY}╷{RESET} ", "", w=8+WIDTH_TOTAL),
|
||||||
Position::Middle => write!(self.0, "\n {GRAY}│{RESET} "),
|
Position::Middle => write!(self.0, "\n {:w$} {GRAY}│{RESET} ", "", w=8+WIDTH_TOTAL),
|
||||||
Position::Last => write!(self.0, "\n {GRAY}╵{RESET} "),
|
Position::Last => write!(self.0, "\n {:w$} {GRAY}╵{RESET} ", "", w=8+WIDTH_TOTAL),
|
||||||
Position::Only => write!(self.0, "{RESET}"),
|
Position::Only => write!(self.0, "{RESET}"),
|
||||||
}.map_err(|_|std::fmt::Error)?;
|
}.map_err(|_|std::fmt::Error)?;
|
||||||
self.0.write(part.as_bytes())
|
self.0.write(part.as_bytes())
|
||||||
|
|||||||
Reference in New Issue
Block a user