diff --git a/ffplayout-api/src/utils/mod.rs b/ffplayout-api/src/utils/mod.rs index 2e0785c3..fea2a35c 100644 --- a/ffplayout-api/src/utils/mod.rs +++ b/ffplayout-api/src/utils/mod.rs @@ -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); diff --git a/ffplayout-engine/src/utils/mod.rs b/ffplayout-engine/src/utils/mod.rs index d97390e1..9df2910e 100644 --- a/ffplayout-engine/src/utils/mod.rs +++ b/ffplayout-engine/src/utils/mod.rs @@ -70,6 +70,7 @@ pub fn get_config(args: Args) -> Result { config.logging.path = log_path; } else { config.logging.log_to_file = false; + config.logging.timestamp = false; } }