feat: follow XDG spec on linux/mac and use windows known folders for config and logs (#1153)

This commit is contained in:
Kalvin C
2025-02-11 08:47:28 -08:00
committed by GitHub
parent 01aeeaf413
commit 54af4c914c
19 changed files with 163 additions and 63 deletions
+10 -10
View File
@@ -1,4 +1,5 @@
use anyhow::{Context, Result};
use etcetera::{choose_app_strategy, AppStrategy};
use std::fs;
use std::path::PathBuf;
use tracing_appender::rolling::Rotation;
@@ -12,17 +13,16 @@ use goose::tracing::langfuse_layer;
/// Returns the directory where log files should be stored.
/// Creates the directory structure if it doesn't exist.
fn get_log_directory() -> Result<PathBuf> {
let home = if cfg!(windows) {
std::env::var("USERPROFILE").context("USERPROFILE environment variable not set")?
} else {
std::env::var("HOME").context("HOME environment variable not set")?
};
// choose_app_strategy().state_dir()
// - macOS/Linux: ~/.local/state/goose/logs/cli
// - Windows: ~\AppData\Roaming\Block\goose\data\logs\cli
// - Windows has no convention for state_dir, use data_dir instead
let home_dir = choose_app_strategy(crate::APP_STRATEGY.clone())
.context("HOME environment variable not set")?;
let base_log_dir = PathBuf::from(home)
.join(".config")
.join("goose")
.join("logs")
.join("cli"); // Add cli-specific subdirectory
let base_log_dir = home_dir
.in_state_dir("logs/cli")
.unwrap_or_else(|| home_dir.in_data_dir("logs/cli"));
// Create date-based subdirectory
let now = chrono::Local::now();