@@ -83,20 +83,25 @@ pub struct LogWriterActor {
83
83
// Sequence counters for stdout and stderr
84
84
stdout_seq : AtomicU64 ,
85
85
stderr_seq : AtomicU64 ,
86
+ // Process ID of the process that generates the logs.
87
+ pid : u32 ,
86
88
}
87
89
88
90
#[ derive( Debug , Clone ) ]
89
91
pub struct LogWriterActorParams {
90
92
mailbox_router : DialMailboxRouter ,
91
93
client : Mailbox ,
94
+ // Process ID of the process that generates the logs.
95
+ pid : u32 ,
92
96
}
93
97
94
98
impl LogWriterActorParams {
95
99
// Constructor for LogWriterActorParams
96
- pub fn new ( mailbox_router : DialMailboxRouter , client : Mailbox ) -> Self {
100
+ pub fn new ( mailbox_router : DialMailboxRouter , client : Mailbox , pid : u32 ) -> Self {
97
101
Self {
98
102
mailbox_router,
99
103
client,
104
+ pid,
100
105
}
101
106
}
102
107
}
@@ -112,6 +117,7 @@ impl Actor for LogWriterActor {
112
117
mailbox_router : params. mailbox_router ,
113
118
stdout_seq : AtomicU64 :: new ( 0 ) ,
114
119
stderr_seq : AtomicU64 :: new ( 0 ) ,
120
+ pid : params. pid ,
115
121
} )
116
122
}
117
123
}
@@ -156,7 +162,7 @@ impl LogWriterMessageHandler for LogWriterActor {
156
162
157
163
// Create the log state object
158
164
let metadata = StateMetadata {
159
- name : Name :: from ( output_target) ,
165
+ name : Name :: from_target_with_pid ( output_target, self . pid ) ,
160
166
kind : Kind :: Log ,
161
167
} ;
162
168
let spec = LogSpec { } ;
@@ -226,14 +232,15 @@ impl StateActorLogSender {
226
232
pub fn new (
227
233
state_actor_addr : ChannelAddr ,
228
234
state_actor_ref : ActorRef < StateActor > ,
235
+ pid : u32 ,
229
236
) -> Result < Self , anyhow:: Error > {
230
237
// Create a LogWriterActor
231
238
let proc_id = id ! ( log_writer_proc) . random_user_proc ( ) ;
232
239
let router = DialMailboxRouter :: new ( ) ;
233
240
let proc = Proc :: new ( proc_id, BoxedMailboxSender :: new ( router. clone ( ) ) ) ;
234
241
// Create client mailbox
235
242
let client = proc. attach ( "client" ) ?;
236
- let log_writer_params = LogWriterActorParams :: new ( router, client. clone ( ) ) ;
243
+ let log_writer_params = LogWriterActorParams :: new ( router, client. clone ( ) , pid ) ;
237
244
238
245
// Spawn the LogWriterActor using our helper function
239
246
let log_writer_handle = futures:: executor:: block_on ( Self :: spawn_log_writer_actor (
@@ -289,13 +296,16 @@ pub struct LogWriter<T: LogSender + Unpin + 'static, S: io::AsyncWrite + Send +
289
296
/// # Arguments
290
297
///
291
298
/// * `state_actor_addr` - The address of the state actor to send logs to
299
+ /// * `state_actor_ref` - A reference to the state actor
300
+ /// * `pid` - The process ID of the process that generates the logs
292
301
///
293
302
/// # Returns
294
303
///
295
304
/// A tuple of boxed writers for stdout and stderr
296
305
pub fn create_log_writers (
297
306
state_actor_addr : ChannelAddr ,
298
307
state_actor_ref : ActorRef < StateActor > ,
308
+ pid : u32 ,
299
309
) -> Result <
300
310
(
301
311
Box < dyn io:: AsyncWrite + Send + Unpin + ' static > ,
@@ -304,7 +314,7 @@ pub fn create_log_writers(
304
314
anyhow:: Error ,
305
315
> {
306
316
// Create a single StateActorLogSender to be shared between stdout and stderr
307
- let log_sender = StateActorLogSender :: new ( state_actor_addr, state_actor_ref) ?;
317
+ let log_sender = StateActorLogSender :: new ( state_actor_addr, state_actor_ref, pid ) ?;
308
318
309
319
// Create LogWriter instances for stdout and stderr using the shared log sender
310
320
let stdout_writer = LogWriter :: with_default_writer ( OutputTarget :: Stdout , log_sender. clone ( ) ) ?;
0 commit comments