limit log file size, fix #504
This commit is contained in:
parent
449561cf11
commit
621af06273
@ -2,7 +2,7 @@ use std::{
|
||||
env,
|
||||
error::Error,
|
||||
fmt,
|
||||
fs::{self, File},
|
||||
fs::{self, metadata, File},
|
||||
io::{stdin, stdout, Write},
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
@ -312,9 +312,16 @@ pub async fn read_log_file(
|
||||
.to_string();
|
||||
log_path.push_str(&date_str);
|
||||
|
||||
let file = fs::read_to_string(log_path)?;
|
||||
let file_size = metadata(&log_path)?.len() as f64;
|
||||
|
||||
return Ok(file);
|
||||
let file_content = if file_size > 5000000.0 {
|
||||
error!("Log file to big: {}", sizeof_fmt(file_size));
|
||||
format!("The log file is larger ({}) than the hard limit of 5MB, the probability is very high that something is wrong with the playout. Check this on the server with `less {log_path}`.", sizeof_fmt(file_size))
|
||||
} else {
|
||||
fs::read_to_string(log_path)?
|
||||
};
|
||||
|
||||
return Ok(file_content);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,6 +330,20 @@ pub async fn read_log_file(
|
||||
))
|
||||
}
|
||||
|
||||
/// get human readable file size
|
||||
pub fn sizeof_fmt(mut num: f64) -> String {
|
||||
let suffix = 'B';
|
||||
|
||||
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"] {
|
||||
if num.abs() < 1024.0 {
|
||||
return format!("{num:.1}{unit}{suffix}");
|
||||
}
|
||||
num /= 1024.0;
|
||||
}
|
||||
|
||||
format!("{num:.1}Yi{suffix}")
|
||||
}
|
||||
|
||||
pub fn local_utc_offset() -> i32 {
|
||||
let mut offset = Local::now().format("%:z").to_string();
|
||||
let operator = offset.remove(0);
|
||||
|
@ -70,6 +70,7 @@ pub fn get_config(args: Args) -> Result<PlayoutConfig, ProcError> {
|
||||
config.logging.path = log_path;
|
||||
} else {
|
||||
config.logging.log_to_file = false;
|
||||
config.logging.timestamp = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user