feat: log rotation (#5561)

This commit is contained in:
Alex Hancock
2025-11-04 14:59:44 -05:00
committed by GitHub
parent ff49fa1617
commit cd2ea778f0
4 changed files with 50 additions and 47 deletions
+2 -4
View File
@@ -1,6 +1,5 @@
use super::base::Usage;
use super::errors::GoogleErrorCode;
use crate::config::paths::Paths;
use crate::model::ModelConfig;
use crate::providers::errors::{OpenAIError, ProviderError};
use anyhow::{anyhow, Result};
@@ -471,8 +470,7 @@ impl RequestLog {
where
Payload: Serialize,
{
let logs_dir = Paths::in_state_dir("logs");
std::fs::create_dir_all(&logs_dir)?;
let logs_dir = crate::logging::prepare_log_directory("llm", true)?;
let request_id = Uuid::new_v4();
let temp_name = format!("llm_request.{request_id}.jsonl");
@@ -529,7 +527,7 @@ impl RequestLog {
fn finish(&mut self) -> Result<()> {
if let Some(mut writer) = self.writer.take() {
writer.flush()?;
let logs_dir = Paths::in_state_dir("logs");
let logs_dir = crate::logging::prepare_log_directory("llm", true)?;
let log_path = |i| logs_dir.join(format!("llm_request.{}.jsonl", i));
for i in (0..LOGS_TO_KEEP - 1).rev() {