1010#[ cfg( feature = "server" ) ]
1111use std:: net:: IpAddr ;
1212use std:: num:: NonZeroU128 ;
13+ use std:: path:: PathBuf ;
1314
1415use clap:: Args ;
1516use katana_genesis:: Genesis ;
@@ -30,7 +31,7 @@ use katana_primitives::block::{BlockHashOrNumber, GasPrice};
3031use katana_primitives:: chain:: ChainId ;
3132#[ cfg( feature = "server" ) ]
3233use katana_rpc_server:: cors:: HeaderValue ;
33- use katana_tracing:: { gcloud, otlp, LogFormat , TracerConfig } ;
34+ use katana_tracing:: { default_log_file_directory , gcloud, otlp, LogColor , LogFormat , TracerConfig } ;
3435use serde:: { Deserialize , Serialize } ;
3536use serde_utils:: serialize_opt_as_hex;
3637use url:: Url ;
@@ -41,6 +42,7 @@ use crate::utils::{parse_block_hash_or_number, parse_genesis};
4142
4243const DEFAULT_DEV_SEED : & str = "0" ;
4344const DEFAULT_DEV_ACCOUNTS : u16 = 10 ;
45+ const DEFAULT_LOG_FILE_MAX_FILES : usize = 7 ;
4446
4547#[ cfg( feature = "server" ) ]
4648#[ derive( Debug , Args , Clone , Serialize , Deserialize , PartialEq ) ]
@@ -433,11 +435,59 @@ pub struct ForkingOptions {
433435#[ derive( Debug , Args , Clone , Serialize , Deserialize , Default , PartialEq ) ]
434436#[ command( next_help_heading = "Logging options" ) ]
435437pub struct LoggingOptions {
436- /// Log format to use
437- #[ arg( long = "log.format" , value_name = "FORMAT" ) ]
438+ #[ command( flatten) ]
439+ pub stdout : StdoutLoggingOptions ,
440+
441+ #[ command( flatten) ]
442+ pub file : FileLoggingOptions ,
443+ }
444+
445+ #[ derive( Debug , Args , Clone , Serialize , Deserialize , Default , PartialEq ) ]
446+ pub struct StdoutLoggingOptions {
447+ #[ arg( long = "log.stdout.format" , value_name = "FORMAT" ) ]
448+ #[ arg( default_value_t = LogFormat :: Full ) ]
449+ pub stdout_format : LogFormat ,
450+
451+ /// Sets whether or not the formatter emits ANSI terminal escape codes for colors and other
452+ /// text formatting
453+ ///
454+ /// Possible values:
455+ /// - always: Colors on
456+ /// - auto: Auto-detect
457+ /// - never: Colors off
458+ #[ arg( long = "color" , value_name = "COLOR" ) ]
459+ #[ arg( default_value_t = LogColor :: Always ) ]
460+ pub color : LogColor ,
461+ }
462+
463+ #[ derive( Debug , Args , Clone , Serialize , Deserialize , Default , PartialEq ) ]
464+ pub struct FileLoggingOptions {
465+ /// Enable writing logs to files.
466+ #[ arg( long = "log.file" ) ]
467+ #[ serde( default ) ]
468+ pub enabled : bool ,
469+
470+ #[ arg( requires = "enabled" ) ]
471+ #[ arg( long = "log.file.format" , value_name = "FORMAT" ) ]
438472 #[ arg( default_value_t = LogFormat :: Full ) ]
439- pub log_format : LogFormat ,
473+ pub file_format : LogFormat ,
474+
475+ /// The path to put log files in
476+ #[ arg( requires = "enabled" ) ]
477+ #[ arg( long = "log.file.directory" , value_name = "PATH" ) ]
478+ #[ arg( default_value_os_t = default_log_file_directory( ) ) ]
479+ #[ serde( default = "default_log_file_directory" ) ]
480+ pub directory : PathBuf ,
481+
482+ /// Maximum number of daily log files to keep.
483+ ///
484+ /// If `0` is supplied, no files are deleted (unlimited retention).
485+ #[ arg( requires = "enabled" ) ]
486+ #[ arg( long = "log.file.max-files" , value_name = "COUNT" ) ]
487+ #[ arg( default_value_t = DEFAULT_LOG_FILE_MAX_FILES ) ]
488+ pub max_files : usize ,
440489}
490+
441491#[ derive( Debug , Args , Default , Clone , Serialize , Deserialize , PartialEq ) ]
442492#[ command( next_help_heading = "Gas Price Oracle Options" ) ]
443493pub struct GasPriceOracleOptions {
0 commit comments