fix: Replace single-letter log levels with full words
Change E/I/T to error/info/trace/warn/debug for readability. Update indent from 21 to 25 spaces to accommodate longer level strings.
This commit is contained in:
parent
a1ddd1cdd0
commit
f5496b0177
1 changed files with 12 additions and 20 deletions
|
|
@ -3,12 +3,12 @@ use log::Record;
|
|||
use std::io::Write;
|
||||
|
||||
pub fn compact_format(buf: &mut Formatter, record: &Record) -> std::io::Result<()> {
|
||||
let level_char = match record.level() {
|
||||
log::Level::Error => 'E',
|
||||
log::Level::Warn => 'I', // Mapping Warn to Info per I/T/E spec
|
||||
log::Level::Info => 'I',
|
||||
log::Level::Debug => 'T', // Mapping Debug to Trace per I/T/E spec
|
||||
log::Level::Trace => 'T',
|
||||
let level_str = match record.level() {
|
||||
log::Level::Error => "error",
|
||||
log::Level::Warn => "warn",
|
||||
log::Level::Info => "info",
|
||||
log::Level::Debug => "debug",
|
||||
log::Level::Trace => "trace",
|
||||
};
|
||||
|
||||
let now = chrono::Local::now();
|
||||
|
|
@ -21,22 +21,14 @@ pub fn compact_format(buf: &mut Formatter, record: &Record) -> std::io::Result<(
|
|||
target
|
||||
};
|
||||
|
||||
// Format: "YYYYMMDDHHMMSS.mmm L module:"
|
||||
// Length: 18 + 1 + 1 + 1 + module.len() + 1 = 22 + module.len()
|
||||
let prefix = format!("{} {} {}:", timestamp, level_char, module);
|
||||
// Format: "YYYYMMDDHHMMSS.mmm level module:"
|
||||
// Length: 18 + 1 + 5 (error) + 1 + module.len() + 1 = 26 + module.len()
|
||||
let prefix = format!("{} {} {}:", timestamp, level_str, module);
|
||||
|
||||
// Max width 100
|
||||
// If prefix + message fits, print it.
|
||||
// Else, wrap.
|
||||
// Indent for wrapping is 21 spaces (18 timestamp + 1 space + 1 level + 1 space)
|
||||
// Actually, based on spec:
|
||||
// Position: 123456789012345678901234567890...
|
||||
// Format: YYYYMMDDHHMMSS.mmm L module:Message
|
||||
// 1 18 20 22
|
||||
// So indent is 21 spaces.
|
||||
|
||||
// Indent for wrapping: 18 timestamp + 1 space + 5 (longest level "error") + 1 space = 25 spaces
|
||||
let message = record.args().to_string();
|
||||
let indent = " "; // 21 spaces
|
||||
let indent = " "; // 25 spaces
|
||||
|
||||
if prefix.len() + message.len() <= 100 {
|
||||
writeln!(buf, "{}{}", prefix, message)
|
||||
|
|
@ -46,7 +38,7 @@ pub fn compact_format(buf: &mut Formatter, record: &Record) -> std::io::Result<(
|
|||
} else {
|
||||
0
|
||||
};
|
||||
let available_other_lines = 100 - 21; // 99 chars
|
||||
let available_other_lines = 100 - 25; // 75 chars
|
||||
|
||||
let mut current_pos = 0;
|
||||
let chars: Vec<char> = message.chars().collect();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue