Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #324

Merged
merged 3 commits into from
Jan 3, 2025
Merged

Fix #324

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions atoma-bin/atoma_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use tokio::{
use tracing::{error, info, instrument, warn};
use tracing_appender::{
non_blocking,
non_blocking::WorkerGuard,
rolling::{RollingFileAppender, Rotation},
};
use tracing_subscriber::{
Expand Down Expand Up @@ -167,7 +168,8 @@ async fn initialize_tokenizers(

#[tokio::main]
async fn main() -> Result<()> {
setup_logging(LOGS).context("Failed to setup logging")?;
let _log_guards = setup_logging(LOGS).context("Failed to setup logging")?;

dotenv().ok();

let args = Args::parse();
Expand Down Expand Up @@ -437,15 +439,18 @@ async fn main() -> Result<()> {
}

/// Configure logging with JSON formatting, file output, and console output
fn setup_logging<P: AsRef<Path>>(log_dir: P) -> Result<()> {
fn setup_logging<P: AsRef<Path>>(log_dir: P) -> Result<(WorkerGuard, WorkerGuard)> {
// Create logs directory if it doesn't exist
std::fs::create_dir_all(&log_dir).context("Failed to create logs directory")?;

// Set up file appenders with rotation for both services
let node_appender = RollingFileAppender::new(Rotation::DAILY, log_dir.as_ref(), NODE_LOG_FILE);
let daemon_appender =
RollingFileAppender::new(Rotation::DAILY, log_dir.as_ref(), DAEMON_LOG_FILE);

// Create non-blocking writers
let (node_non_blocking, _node_guard) = non_blocking(node_appender);
let (daemon_non_blocking, _daemon_guard) = non_blocking(daemon_appender);
// Create non-blocking writers and keep the guards
let (node_non_blocking, node_guard) = non_blocking(node_appender);
let (daemon_non_blocking, daemon_guard) = non_blocking(daemon_appender);

// Create JSON formatter for node service
let node_layer = fmt::layer()
Expand All @@ -459,7 +464,7 @@ fn setup_logging<P: AsRef<Path>>(log_dir: P) -> Result<()> {
.with_current_span(true)
.with_span_list(true)
.with_writer(node_non_blocking)
.with_filter(EnvFilter::new("atoma_node=debug"));
.with_filter(EnvFilter::new("atoma_node=info"));

// Create JSON formatter for daemon service
let daemon_layer = fmt::layer()
Expand All @@ -473,7 +478,7 @@ fn setup_logging<P: AsRef<Path>>(log_dir: P) -> Result<()> {
.with_current_span(true)
.with_span_list(true)
.with_writer(daemon_non_blocking)
.with_filter(EnvFilter::new("atoma_daemon=debug"));
.with_filter(EnvFilter::new("atoma_daemon=info"));

// Create console formatter for development
let console_layer = fmt::layer()
Expand All @@ -495,7 +500,8 @@ fn setup_logging<P: AsRef<Path>>(log_dir: P) -> Result<()> {
.with(daemon_layer)
.init();

Ok(())
// Return the guards so they can be stored in main
Ok((node_guard, daemon_guard))
}

/// Handles the results of various tasks (subscriber, state manager, and server).
Expand Down