11from __future__ import annotations
22
3- from typing import TYPE_CHECKING , Any
3+ from typing import TYPE_CHECKING , Any , Literal
44
55from apify_shared .utils import (
66 filter_out_none_values_recursively ,
2727
2828if TYPE_CHECKING :
2929 from decimal import Decimal
30+ from logging import Logger
3031
3132 from apify_shared .consts import ActorJobStatus , MetaOrigin
3233
@@ -289,6 +290,7 @@ def call(
289290 timeout_secs : int | None = None ,
290291 webhooks : list [dict ] | None = None ,
291292 wait_secs : int | None = None ,
293+ logger : Logger | None | Literal ['default' ] = 'default' ,
292294 ) -> dict | None :
293295 """Start the Actor and wait for it to finish before returning the Run object.
294296
@@ -313,6 +315,9 @@ def call(
313315 a webhook set up for the Actor, you do not have to add it again here.
314316 wait_secs: The maximum number of seconds the server waits for the run to finish. If not provided,
315317 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.
316321
317322 Returns:
318323 The run object.
@@ -327,8 +332,17 @@ def call(
327332 timeout_secs = timeout_secs ,
328333 webhooks = webhooks ,
329334 )
335+ if not logger :
336+ return self .root_client .run (started_run ['id' ]).wait_for_finish (wait_secs = wait_secs )
330337
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 )
332346
333347 def build (
334348 self ,
@@ -681,6 +695,7 @@ async def call(
681695 timeout_secs : int | None = None ,
682696 webhooks : list [dict ] | None = None ,
683697 wait_secs : int | None = None ,
698+ logger : Logger | None | Literal ['default' ] = 'default' ,
684699 ) -> dict | None :
685700 """Start the Actor and wait for it to finish before returning the Run object.
686701
@@ -705,6 +720,9 @@ async def call(
705720 a webhook set up for the Actor, you do not have to add it again here.
706721 wait_secs: The maximum number of seconds the server waits for the run to finish. If not provided,
707722 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.
708726
709727 Returns:
710728 The run object.
@@ -720,7 +738,17 @@ async def call(
720738 webhooks = webhooks ,
721739 )
722740
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 )
724752
725753 async def build (
726754 self ,
0 commit comments