Skip to content

Commit

Permalink
draft: complexity tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Dec 21, 2024
1 parent fc99f03 commit 2261945
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,10 @@ impl RecordFormatter {
}
if self.cfg.always_show_time {
self.format_timestamp_stub(&mut fs, s);
fs.complexity += 1 + self.ts_width.chars;
}
} else {
fs.complexity += 1 + self.ts_width.chars;
}

//
Expand All @@ -415,6 +418,7 @@ impl RecordFormatter {
let level = level.or_else(|| self.cfg.always_show_level.then(|| LEVEL_UNKNOWN.as_bytes()));
if let Some(level) = level {
fs.has_level = true;
fs.complexity += 3 + level.len();
self.format_level(s, &mut fs, level);
}

Expand All @@ -428,17 +432,26 @@ impl RecordFormatter {
s.batch(|buf| buf.extend_from_slice(logger.as_bytes()))
});
s.batch(|buf| buf.extend_from_slice(self.cfg.punctuation.logger_name_separator.as_bytes()));
fs.complexity += logger.len() + 4;
fs.complexity += 2 + logger.len();
fs.first_line_used = true;
});
}

// include caller into cumulative complexity calculation
if let Some(caller) = &rec.caller {
fs.complexity += 3 + match caller {
Caller::Text(text) => text.len(),
Caller::FileLine(file, line) => file.len() + line.len() + 1,
};
}

//
// message text
//
if let Some(value) = &rec.message {
match fs.transact(s, |fs, s| self.format_message(s, fs, *value)) {
Ok(()) => {
fs.complexity += 4;
fs.complexity += 2;
fs.first_line_used = true;
}
Err(MessageFormatError::ExpansionNeeded) => {
Expand Down Expand Up @@ -968,7 +981,7 @@ impl<'a> FieldFormatter<'a> {

let ffv = self.begin(s, key, value, fs);

fs.complexity += key.len() + 4;
fs.complexity += key.len() + 2;

let result = if self.rf.cfg.unescape_fields {
self.format_value(s, value, fs, filter, setting)
Expand Down

0 comments on commit 2261945

Please sign in to comment.