refactor: improve logging
Release / check-release (push) Successful in 15s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m43s
CI / Build Linux (push) Successful in 1m56s

This commit is contained in:
Elias Wendland committed 2026-07-16 14:43:58 +02:00
1 parent d3b7d7a18f
commit b65d5eb97c
8 files changed
+198 -44

No files matched your search

+41 -9
View File
@@ -40,11 +40,15 @@ impl Plugin for PluginImpl {
]
}
#[tracing::instrument(skip(self))]
fn is_available(&self) -> bool {
std::process::Command::new("ffmpeg")
tracing::trace!("Checking availability of ffmpeg for ffmpeg_audio plugin");
let available = std::process::Command::new("ffmpeg")
.arg("-version")
.output()
.is_ok()
.is_ok();
tracing::debug!("ffmpeg_audio plugin available: {}", available);
available
}
fn familiarity(&self, _from: &str, to: &str) -> u8 {
@@ -82,6 +86,7 @@ impl Plugin for PluginImpl {
}
}
#[tracing::instrument(skip(self, input, temp_dir))]
fn convert(
&self,
input: &[u8],
@@ -89,19 +94,30 @@ impl Plugin for PluginImpl {
to: &str,
temp_dir: &Path,
) -> Result<Vec<u8>, String> {
tracing::debug!("ffmpeg_audio starting conversion: {} -> {}", _from, to);
let mut temp_in = tempfile::Builder::new()
.suffix(&format!(".{}", _from))
.tempfile_in(temp_dir)
.map_err(|e| e.to_string())?;
temp_in.write_all(input).map_err(|e| e.to_string())?;
.map_err(|e| {
tracing::error!("Failed to create temp input file: {}", e);
e.to_string()
})?;
temp_in.write_all(input).map_err(|e| {
tracing::error!("Failed to write to temp input file: {}", e);
e.to_string()
})?;
let temp_out = tempfile::Builder::new()
.suffix(&format!(".{}", to))
.tempfile_in(temp_dir)
.map_err(|e| e.to_string())?;
.map_err(|e| {
tracing::error!("Failed to create temp output file: {}", e);
e.to_string()
})?;
let temp_out_path = temp_out.into_temp_path();
let in_path = temp_in.path().to_path_buf();
tracing::trace!("Temp files created. In: {:?}, Out: {:?}", in_path, temp_out_path);
let mut raw_args = vec![];
match to {
@@ -134,19 +150,35 @@ impl Plugin for PluginImpl {
_ => raw_args.extend(vec!["-c:a", "copy"]),
}
let rt = tokio::runtime::Runtime::new().map_err(|e| e.to_string())?;
tracing::debug!("Built ffmpeg arguments: {:?}", raw_args);
let rt = tokio::runtime::Runtime::new().map_err(|e| {
tracing::error!("Failed to create Tokio runtime: {}", e);
e.to_string()
})?;
rt.block_on(async {
tracing::trace!("Executing FFmpegBuilder...");
FFmpegBuilder::new()
.map_err(|e| e.to_string())?
.map_err(|e| {
tracing::error!("Failed to init FFmpegBuilder: {}", e);
e.to_string()
})?
.input_path(in_path)
.output_path(temp_out_path.to_path_buf())
.raw_args(raw_args)
.overwrite()
.run()
.await
.map_err(|e| e.to_string())
.map_err(|e| {
tracing::error!("FFmpeg execution failed: {}", e);
e.to_string()
})
})?;
std::fs::read(&temp_out_path).map_err(|e| e.to_string())
tracing::debug!("FFmpeg execution succeeded. Reading output file...");
std::fs::read(&temp_out_path).map_err(|e| {
tracing::error!("Failed to read output file {:?}: {}", temp_out_path, e);
e.to_string()
})
}
}
+41 -9
View File
@@ -38,11 +38,15 @@ impl Plugin for PluginImpl {
]
}
#[tracing::instrument(skip(self))]
fn is_available(&self) -> bool {
std::process::Command::new("ffmpeg")
tracing::trace!("Checking availability of ffmpeg for ffmpeg_video plugin");
let available = std::process::Command::new("ffmpeg")
.arg("-version")
.output()
.is_ok()
.is_ok();
tracing::debug!("ffmpeg_video plugin available: {}", available);
available
}
fn familiarity(&self, _from: &str, to: &str) -> u8 {
@@ -84,6 +88,7 @@ impl Plugin for PluginImpl {
}
}
#[tracing::instrument(skip(self, input, temp_dir))]
fn convert(
&self,
input: &[u8],
@@ -91,19 +96,30 @@ impl Plugin for PluginImpl {
to: &str,
temp_dir: &Path,
) -> Result<Vec<u8>, String> {
tracing::debug!("ffmpeg_video starting conversion: {} -> {}", _from, to);
let mut temp_in = tempfile::Builder::new()
.suffix(&format!(".{}", _from))
.tempfile_in(temp_dir)
.map_err(|e| e.to_string())?;
temp_in.write_all(input).map_err(|e| e.to_string())?;
.map_err(|e| {
tracing::error!("Failed to create temp input file: {}", e);
e.to_string()
})?;
temp_in.write_all(input).map_err(|e| {
tracing::error!("Failed to write to temp input file: {}", e);
e.to_string()
})?;
let temp_out = tempfile::Builder::new()
.suffix(&format!(".{}", to))
.tempfile_in(temp_dir)
.map_err(|e| e.to_string())?;
.map_err(|e| {
tracing::error!("Failed to create temp output file: {}", e);
e.to_string()
})?;
let temp_out_path = temp_out.into_temp_path();
let in_path = temp_in.path().to_path_buf();
tracing::trace!("Temp files created. In: {:?}, Out: {:?}", in_path, temp_out_path);
let mut raw_args = vec![];
match to {
@@ -222,19 +238,35 @@ impl Plugin for PluginImpl {
}
}
let rt = tokio::runtime::Runtime::new().map_err(|e| e.to_string())?;
tracing::debug!("Built ffmpeg arguments: {:?}", raw_args);
let rt = tokio::runtime::Runtime::new().map_err(|e| {
tracing::error!("Failed to create Tokio runtime: {}", e);
e.to_string()
})?;
rt.block_on(async {
tracing::trace!("Executing FFmpegBuilder...");
FFmpegBuilder::new()
.map_err(|e| e.to_string())?
.map_err(|e| {
tracing::error!("Failed to init FFmpegBuilder: {}", e);
e.to_string()
})?
.input_path(in_path)
.output_path(temp_out_path.to_path_buf())
.raw_args(raw_args)
.overwrite()
.run()
.await
.map_err(|e| e.to_string())
.map_err(|e| {
tracing::error!("FFmpeg execution failed: {}", e);
e.to_string()
})
})?;
std::fs::read(&temp_out_path).map_err(|e| e.to_string())
tracing::debug!("FFmpeg execution succeeded. Reading output file...");
std::fs::read(&temp_out_path).map_err(|e| {
tracing::error!("Failed to read output file {:?}: {}", temp_out_path, e);
e.to_string()
})
}
}
+27 -5
View File
@@ -20,6 +20,12 @@ use std::path::Path;
pub struct PluginImpl;
impl Plugin for PluginImpl {
#[tracing::instrument(skip(self))]
fn is_available(&self) -> bool {
tracing::trace!("Checking availability for jpeg_to_png plugin (always true)");
true
}
fn name(&self) -> &'static str {
"jpeg_to_png"
}
@@ -39,6 +45,7 @@ impl Plugin for PluginImpl {
200
}
#[tracing::instrument(skip(self, input, _temp_dir))]
fn convert(
&self,
input: &[u8],
@@ -46,11 +53,26 @@ impl Plugin for PluginImpl {
_to: &str,
_temp_dir: &Path,
) -> Result<Vec<u8>, String> {
tracing::debug!("jpeg_to_png starting conversion");
tracing::trace!("Loading JPEG image from memory ({} bytes)", input.len());
let img = image::load_from_memory_with_format(input, ImageFormat::Jpeg)
.map_err(|e| e.to_string())?;
let mut buf = Vec::new();
img.write_to(&mut Cursor::new(&mut buf), ImageFormat::Png)
.map_err(|e| e.to_string())?;
Ok(buf)
.map_err(|e| {
tracing::error!("Failed to decode JPEG image: {}", e);
e.to_string()
})?;
tracing::trace!("JPEG image loaded successfully. Dimensions: {}x{}", img.width(), img.height());
let mut output = Cursor::new(Vec::new());
tracing::trace!("Encoding image as PNG");
img.write_to(&mut output, ImageFormat::Png)
.map_err(|e| {
tracing::error!("Failed to encode image as PNG: {}", e);
e.to_string()
})?;
let out_bytes = output.into_inner();
tracing::debug!("jpeg_to_png conversion completed. Output size: {} bytes", out_bytes.len());
Ok(out_bytes)
}
}
+28 -10
View File
@@ -13,13 +13,15 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::plugin::Plugin;
use image::ImageFormat;
use std::io::Cursor;
use std::path::Path;
pub struct PluginImpl;
impl Plugin for PluginImpl {
#[tracing::instrument(skip(self))]
fn is_available(&self) -> bool {
tracing::trace!("Checking availability for png_to_jpeg plugin (always true)");
true
}
fn name(&self) -> &'static str {
"png_to_jpeg"
}
@@ -39,18 +41,34 @@ impl Plugin for PluginImpl {
220
}
#[tracing::instrument(skip(self, input, _temp_dir))]
fn convert(
&self,
input: &[u8],
_from: &str,
_to: &str,
_temp_dir: &Path,
_temp_dir: &std::path::Path,
) -> Result<Vec<u8>, String> {
let img = image::load_from_memory_with_format(input, ImageFormat::Png)
.map_err(|e| e.to_string())?;
let mut buf = Vec::new();
img.write_to(&mut Cursor::new(&mut buf), ImageFormat::Jpeg)
.map_err(|e| e.to_string())?;
Ok(buf)
tracing::debug!("png_to_jpeg starting conversion");
tracing::trace!("Loading PNG image from memory ({} bytes)", input.len());
let img = image::load_from_memory_with_format(input, image::ImageFormat::Png)
.map_err(|e| {
tracing::error!("Failed to decode PNG image: {}", e);
e.to_string()
})?;
tracing::trace!("PNG image loaded successfully. Dimensions: {}x{}", img.width(), img.height());
let mut output = std::io::Cursor::new(Vec::new());
tracing::trace!("Encoding image as JPEG");
img.write_to(&mut output, image::ImageFormat::Jpeg)
.map_err(|e| {
tracing::error!("Failed to encode image as JPEG: {}", e);
e.to_string()
})?;
let out_bytes = output.into_inner();
tracing::debug!("png_to_jpeg conversion completed. Output size: {} bytes", out_bytes.len());
Ok(out_bytes)
}
}