simplify code

This commit is contained in:
jb-alvarado 2022-10-25 15:05:10 +02:00
parent 4b92c7efd2
commit 17303aa8d5
3 changed files with 17 additions and 40 deletions

View File

@ -9,37 +9,27 @@ use crossbeam_channel::Sender;
use simplelog::*;
use ffplayout_lib::utils::{
controller::ProcessUnit::*, format_log_line, test_tcp_port, Media, PlayoutConfig,
ProcessControl,
controller::ProcessUnit::*, test_tcp_port, Media, PlayoutConfig, ProcessControl,
};
use ffplayout_lib::vec_strings;
pub fn log_line(line: String, level: &str) {
if line.contains("[info]") && level.to_lowercase() == "info" {
info!(
"<bright black>[Server]</> {}",
format_log_line(line, "info")
)
info!("<bright black>[Server]</> {}", line.replace("[info] ", ""))
} else if line.contains("[warning]")
&& (level.to_lowercase() == "warning" || level.to_lowercase() == "info")
{
warn!(
"<bright black>[Server]</> {}",
format_log_line(line, "warning")
line.replace("[warning] ", "")
)
} else if line.contains("[error]")
&& !line.contains("Input/output error")
&& !line.contains("Broken pipe")
{
error!(
"<bright black>[Server]</> {}",
format_log_line(line, "error")
);
error!("<bright black>[Server]</> {}", line.replace("[error] ", ""));
} else if line.contains("[fatal]") {
error!(
"<bright black>[Server]</> {}",
format_log_line(line, "fatal")
)
error!("<bright black>[Server]</> {}", line.replace("[fatal] ", ""))
}
}
@ -56,10 +46,7 @@ fn server_monitor(
error!("{e}");
};
warn!(
"<bright black>[Server]</> {}",
format_log_line(line.clone(), "error")
);
warn!("<bright black>[Server]</> {}", line.replace("[error] ", ""));
}
if line.contains("Address already in use") {

View File

@ -10,8 +10,8 @@ use std::{
use simplelog::*;
use crate::utils::{
format_log_line, loop_image, sec_to_time, seek_and_length, valid_source, vec_strings,
JsonPlaylist, Media, OutputMode::Null, PlayoutConfig, FFMPEG_IGNORE_ERRORS, IMAGE_FORMAT,
loop_image, sec_to_time, seek_and_length, valid_source, vec_strings, JsonPlaylist, Media,
OutputMode::Null, PlayoutConfig, FFMPEG_IGNORE_ERRORS, IMAGE_FORMAT,
};
/// check if ffmpeg can read the file and apply filter to it.
@ -82,19 +82,13 @@ fn check_media(
for line in enc_err.lines() {
let line = line?;
if !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i)) {
if line.contains("[error]") {
let log_line = format_log_line(line, "error");
if !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i))
&& (line.contains("[error]") || line.contains("[fatal]"))
{
let log_line = line.replace("[error] ", "").replace("[fatal] ", "");
if !error_list.contains(&log_line) {
error_list.push(log_line);
}
} else if line.contains("[fatal]") {
let log_line = format_log_line(line, "fatal");
if !error_list.contains(&log_line) {
error_list.push(log_line);
}
if !error_list.contains(&log_line) {
error_list.push(log_line);
}
}
}

View File

@ -630,10 +630,6 @@ pub fn include_file(config: PlayoutConfig, file_path: &Path) -> bool {
include
}
pub fn format_log_line(line: String, level: &str) -> String {
line.replace(&format!("[{level: >5}] "), "")
}
/// Read ffmpeg stderr decoder and encoder instance
/// and log the output.
pub fn stderr_reader(
@ -647,19 +643,19 @@ pub fn stderr_reader(
if line.contains("[info]") {
info!(
"<bright black>[{suffix}]</> {}",
format_log_line(line, "info")
line.replace("[info] ", "")
)
} else if line.contains("[warning]") {
warn!(
"<bright black>[{suffix}]</> {}",
format_log_line(line, "warning")
line.replace("[warning] ", "")
)
} else if (line.contains("[error]") || line.contains("[fatal]"))
&& !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i))
{
error!(
"<bright black>[{suffix}]</> {}",
line.replace("[error]", "").replace("[fatal]", "")
line.replace("[error] ", "").replace("[fatal] ", "")
);
if line.contains("Invalid argument")