Skip to main content

endpoint_libs/libs/log/
legacy.rs

1//! Deprecated logging utilities from previous implementations
2
3use std::path::PathBuf;
4use std::sync::Arc;
5
6pub enum LoggingGuard {
7    NonBlocking(tracing_appender::non_blocking::WorkerGuard, PathBuf),
8    StdoutWithPath(Option<PathBuf>),
9}
10impl LoggingGuard {
11    pub fn get_file(&self) -> Option<PathBuf> {
12        match self {
13            LoggingGuard::NonBlocking(_guard, path) => Some(path.clone()),
14            LoggingGuard::StdoutWithPath(path) => path.clone(),
15        }
16    }
17}
18
19#[derive(Clone)]
20pub struct DynLogger {
21    logger: Arc<dyn Fn(&str) + Send + Sync>,
22}
23impl DynLogger {
24    pub fn new(logger: Arc<dyn Fn(&str) + Send + Sync>) -> Self {
25        Self { logger }
26    }
27    pub fn empty() -> Self {
28        Self {
29            logger: Arc::new(|_| {}),
30        }
31    }
32    pub fn log(&self, msg: impl AsRef<str>) {
33        (self.logger)(msg.as_ref())
34    }
35}
36
37/// actually test writing, there is no direct way to check if the application has the ownership or the write access
38pub fn can_create_file_in_directory(directory: &str) -> bool {
39    let test_file_path: String = format!("{directory}/test_file.txt");
40    match std::fs::File::create(&test_file_path) {
41        Ok(file) => {
42            // File created successfully; remove it after checking
43            drop(file);
44            if let Err(err) = std::fs::remove_file(&test_file_path) {
45                eprintln!("Error deleting test file: {err}");
46            }
47            true
48        }
49        Err(_) => false,
50    }
51}