1
1
from __future__ import annotations
2
2
3
- from typing import TYPE_CHECKING , Any
3
+ from typing import TYPE_CHECKING , Any , Literal
4
4
5
5
from apify_shared .utils import (
6
6
filter_out_none_values_recursively ,
27
27
28
28
if TYPE_CHECKING :
29
29
from decimal import Decimal
30
+ from logging import Logger
30
31
31
32
from apify_shared .consts import ActorJobStatus , MetaOrigin
32
33
@@ -289,6 +290,7 @@ def call(
289
290
timeout_secs : int | None = None ,
290
291
webhooks : list [dict ] | None = None ,
291
292
wait_secs : int | None = None ,
293
+ logger : Logger | None | Literal ['default' ] = 'default' ,
292
294
) -> dict | None :
293
295
"""Start the Actor and wait for it to finish before returning the Run object.
294
296
@@ -313,6 +315,9 @@ def call(
313
315
a webhook set up for the Actor, you do not have to add it again here.
314
316
wait_secs: The maximum number of seconds the server waits for the run to finish. If not provided,
315
317
waits indefinitely.
318
+ logger: Logger used to redirect logs from the Actor run. Using "default" literal means that a predefined
319
+ default logger will be used. Setting `None` will disable any log propagation. Passing custom logger
320
+ will redirect logs to the provided logger.
316
321
317
322
Returns:
318
323
The run object.
@@ -327,8 +332,17 @@ def call(
327
332
timeout_secs = timeout_secs ,
328
333
webhooks = webhooks ,
329
334
)
335
+ if not logger :
336
+ return self .root_client .run (started_run ['id' ]).wait_for_finish (wait_secs = wait_secs )
330
337
331
- return self .root_client .run (started_run ['id' ]).wait_for_finish (wait_secs = wait_secs )
338
+ run_client = self .root_client .run (run_id = started_run ['id' ])
339
+ if logger == 'default' :
340
+ log_context = run_client .get_streamed_log ()
341
+ else :
342
+ log_context = run_client .get_streamed_log (to_logger = logger )
343
+
344
+ with log_context :
345
+ return self .root_client .run (started_run ['id' ]).wait_for_finish (wait_secs = wait_secs )
332
346
333
347
def build (
334
348
self ,
@@ -681,6 +695,7 @@ async def call(
681
695
timeout_secs : int | None = None ,
682
696
webhooks : list [dict ] | None = None ,
683
697
wait_secs : int | None = None ,
698
+ logger : Logger | None | Literal ['default' ] = 'default' ,
684
699
) -> dict | None :
685
700
"""Start the Actor and wait for it to finish before returning the Run object.
686
701
@@ -705,6 +720,9 @@ async def call(
705
720
a webhook set up for the Actor, you do not have to add it again here.
706
721
wait_secs: The maximum number of seconds the server waits for the run to finish. If not provided,
707
722
waits indefinitely.
723
+ logger: Logger used to redirect logs from the Actor run. Using "default" literal means that a predefined
724
+ default logger will be used. Setting `None` will disable any log propagation. Passing custom logger
725
+ will redirect logs to the provided logger.
708
726
709
727
Returns:
710
728
The run object.
@@ -720,7 +738,17 @@ async def call(
720
738
webhooks = webhooks ,
721
739
)
722
740
723
- return await self .root_client .run (started_run ['id' ]).wait_for_finish (wait_secs = wait_secs )
741
+ if not logger :
742
+ return await self .root_client .run (started_run ['id' ]).wait_for_finish (wait_secs = wait_secs )
743
+
744
+ run_client = self .root_client .run (run_id = started_run ['id' ])
745
+ if logger == 'default' :
746
+ log_context = await run_client .get_streamed_log ()
747
+ else :
748
+ log_context = await run_client .get_streamed_log (to_logger = logger )
749
+
750
+ async with log_context :
751
+ return await self .root_client .run (started_run ['id' ]).wait_for_finish (wait_secs = wait_secs )
724
752
725
753
async def build (
726
754
self ,
0 commit comments