use crate::logger::{BoxError, LogRecord, LogValue, Processor};
use super::memory_common::{current_process_memory, format_memory, MemoryOptions};
#[derive(Default)]
pub struct MemoryUsage {
options: MemoryOptions,
}
impl MemoryUsage {
pub fn new(real_usage: bool, use_formatting: bool) -> Self {
Self {
options: MemoryOptions {
real_usage,
use_formatting,
},
}
}
}
impl Processor for MemoryUsage {
fn process(&self, mut record: LogRecord) -> Result<LogRecord, BoxError> {
if let Some(bytes) = current_process_memory(self.options.real_usage) {
let value = if self.options.use_formatting {
format_memory(bytes)
} else {
LogValue::U64(bytes)
};
record.extra.insert("memory_usage".to_string(), value);
}
Ok(record)
}
}