use crate::discarded_prune_limits::Limits;
use crate::discarded_prune_plan::Reason;
use crate::iso_time::format_iso_milliseconds;
use crate::json_record::{quote, string_array};
use crate::service_protocol::RELEASE;
use std::path::PathBuf;
const LISTED_COPIES: usize = 100;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Removed {
pub path: PathBuf,
pub bytes: u128,
pub reason: Reason,
}
pub fn prune_line(removed: &Removed, copies: &[String], limits: Limits, folder_bytes: u128, now_millis: i64) -> String {
return audit_line("pruned", removed, copies, limits, folder_bytes, now_millis);
}
pub fn audit_line(outcome: &str, removed: &Removed, copies: &[String], limits: Limits, folder_bytes: u128, now_millis: i64) -> String {
let limit: u64 = match removed.reason {
Reason::Age => limits.max_age_days,
Reason::Size => limits.max_bytes,
};
let listed: Vec<String> = copies.iter().take(LISTED_COPIES).cloned().collect();
return format!(
"{{\"schemaVersion\":1,\"time\":{},\"level\":\"info\",\"timeMillis\":{},\"release\":{},\"pid\":{},\"form\":\"PruneDiscarded\",\
\"outcome\":{},\"reason\":{},\"limit\":{limit},\"folderBytes\":{folder_bytes},\"path\":{},\"bytes\":{},\
\"copiesTotal\":{},\"copies\":{}}}\n",
quote(&format_iso_milliseconds(now_millis)),
quote(&now_millis.to_string()),
quote(RELEASE),
std::process::id(),
quote(outcome),
quote(removed.reason.word()),
quote(&removed.path.to_string_lossy()),
removed.bytes,
copies.len(),
string_array(&listed),
);
}