mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-10-24 22:00:43 +08:00
33 lines
824 B
Rust
33 lines
824 B
Rust
use std::fs;
|
|
use std::time::SystemTime;
|
|
|
|
use anyhow::bail;
|
|
|
|
use homedir::my_home;
|
|
|
|
use log::LevelFilter;
|
|
|
|
const PATH: &str = ".radicle-tui/logs";
|
|
const PREFIX: &str = "rad-tui-";
|
|
|
|
/// Enables logging to `$HOME/.radicle-tui/logs/`. Creates folder if it does not
|
|
/// exist.
|
|
pub fn enable() -> Result<(), anyhow::Error> {
|
|
match my_home()? {
|
|
Some(home) => {
|
|
let path = format!("{}/{}", home.to_string_lossy(), PATH);
|
|
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
|
|
|
|
fs::create_dir_all(path.clone())?;
|
|
|
|
simple_logging::log_to_file(
|
|
format!("{}/{}{}.log", path, PREFIX, now.as_millis()),
|
|
LevelFilter::Info,
|
|
)?;
|
|
|
|
Ok(())
|
|
}
|
|
None => bail!("Failed to read home directory"),
|
|
}
|
|
}
|