@@ -29,22 +29,88 @@ pub struct EventLogger {
2929 _project_root : PathBuf ,
3030 _job_id : String ,
3131 _session_id : Option < String > ,
32+ verbosity : u8 ,
3233}
3334
3435impl EventLogger {
3536 /// Create a new event logger
36- pub fn new ( project_root : PathBuf , job_id : String , session_id : Option < String > ) -> Self {
37+ pub fn new (
38+ project_root : PathBuf ,
39+ job_id : String ,
40+ session_id : Option < String > ,
41+ verbosity : u8 ,
42+ ) -> Self {
3743 Self {
3844 _project_root : project_root,
3945 _job_id : job_id,
4046 _session_id : session_id,
47+ verbosity,
4148 }
4249 }
4350
44- /// Log an event
51+ /// Log an event with verbosity control
4552 pub async fn log_event ( & self , event : MapReduceEvent ) -> Result < ( ) > {
46- // For now, just log to tracing
47- tracing:: info!( "MapReduce event: {:?}" , event) ;
53+ // Always log errors regardless of verbosity
54+ if matches ! ( event, MapReduceEvent :: AgentFailed { .. } ) {
55+ tracing:: info!( "MapReduce event: {:?}" , event) ;
56+ return Ok ( ( ) ) ;
57+ }
58+
59+ // Only log verbose events in verbose mode (verbosity >= 1)
60+ if self . verbosity >= 1 {
61+ match & event {
62+ MapReduceEvent :: AgentCompleted {
63+ agent_id,
64+ item_id,
65+ duration,
66+ cleanup_status,
67+ commits,
68+ json_log_location,
69+ ..
70+ } => {
71+ // Truncate commit list if it's too long (unless verbosity >= 2)
72+ let commits_display = if commits. len ( ) > 10 && self . verbosity < 2 {
73+ format ! (
74+ "[{:?}, {:?}, ... ({} more)]" ,
75+ commits. first( ) . unwrap_or( & String :: new( ) ) ,
76+ commits. get( 1 ) . unwrap_or( & String :: new( ) ) ,
77+ commits. len( ) - 2
78+ )
79+ } else {
80+ format ! ( "{:?}" , commits)
81+ } ;
82+
83+ tracing:: info!(
84+ "MapReduce event: AgentCompleted {{ agent_id: {:?}, item_id: {:?}, duration: {:?}, cleanup_status: {:?}, commits: {}, json_log_location: {:?} }}" ,
85+ agent_id,
86+ item_id,
87+ duration,
88+ cleanup_status,
89+ commits_display,
90+ json_log_location
91+ ) ;
92+ }
93+ _ => {
94+ tracing:: info!( "MapReduce event: {:?}" , event) ;
95+ }
96+ }
97+ } else {
98+ // In default mode, only log phase-level events
99+ match event {
100+ MapReduceEvent :: MapPhaseStarted { .. }
101+ | MapReduceEvent :: MapPhaseCompleted { .. }
102+ | MapReduceEvent :: ReducePhaseStarted { .. }
103+ | MapReduceEvent :: ReducePhaseCompleted { .. } => {
104+ tracing:: info!( "MapReduce event: {:?}" , event) ;
105+ }
106+ // Suppress AgentStarted, AgentCompleted, and AgentFailed in default mode
107+ // (AgentFailed is already handled above and always shown)
108+ MapReduceEvent :: AgentStarted { .. }
109+ | MapReduceEvent :: AgentCompleted { .. }
110+ | MapReduceEvent :: AgentFailed { .. } => { }
111+ }
112+ }
113+
48114 Ok ( ( ) )
49115 }
50116}
0 commit comments