feat: log rotation (#5561)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use anyhow::{Context, Result};
|
||||
use std::path::PathBuf;
|
||||
use tracing_appender::rolling::Rotation;
|
||||
use tracing_subscriber::{
|
||||
filter::LevelFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer,
|
||||
@@ -8,32 +7,24 @@ use tracing_subscriber::{
|
||||
|
||||
use goose::tracing::{langfuse_layer, otlp_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> {
|
||||
goose::logging::get_log_directory("server", true)
|
||||
}
|
||||
|
||||
/// Sets up the logging infrastructure for the application.
|
||||
/// This includes:
|
||||
/// - File-based logging with JSON formatting (DEBUG level)
|
||||
/// - Console output for development (INFO level)
|
||||
/// - Optional Langfuse integration (DEBUG level)
|
||||
pub fn setup_logging(name: Option<&str>) -> Result<()> {
|
||||
// Set up file appender for goose module logs
|
||||
let log_dir = get_log_directory()?;
|
||||
let log_dir = goose::logging::prepare_log_directory("server", true)?;
|
||||
let timestamp = chrono::Local::now().format("%Y%m%d_%H%M%S").to_string();
|
||||
|
||||
// Create log file name by prefixing with timestamp
|
||||
let log_filename = if name.is_some() {
|
||||
format!("{}-{}.log", timestamp, name.unwrap())
|
||||
} else {
|
||||
format!("{}.log", timestamp)
|
||||
};
|
||||
|
||||
// Create non-rolling file appender for detailed logs
|
||||
let file_appender =
|
||||
tracing_appender::rolling::RollingFileAppender::new(Rotation::NEVER, log_dir, log_filename);
|
||||
let file_appender = tracing_appender::rolling::RollingFileAppender::new(
|
||||
Rotation::NEVER, // we do manual rotation via file naming and cleanup_old_logs
|
||||
log_dir,
|
||||
log_filename,
|
||||
);
|
||||
|
||||
// Create JSON file logging layer
|
||||
let file_layer = fmt::layer()
|
||||
|
||||
Reference in New Issue
Block a user