Skip to content

Commit 62c8abc

Browse files
committed
Finish the guide
1 parent 8de1773 commit 62c8abc

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

docs/03_concepts/10_logging.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ Result:
8787
<!-- markdownlint-enable no-inline-html -->
8888

8989
## Redirect logs from other actor runs
90-
In some situations one Actor is going to start one or more other Actors and wait for them to finish and produce some results. In such cases, you might want to redirect the logs and status messages of the started Actors runs back to the parent Actor run, so that you can see the progress of the started Actors in the parent Actor's logs. This guide will show options how to do it.
90+
In some situations one Actor is going to start one or more other Actors and wait for them to finish and produce some results. In such cases, you might want to redirect the logs and status messages of the started Actors runs back to the parent Actor run, so that you can see the progress of the started Actors' runs in the parent Actor's logs. This guide will show possibilities how to do it.
9191

9292
### Redirecting logs from `Actor.call`
93-
Typical use case for log redirection is to call another Actor using the [`Actor.call`](../../reference/class/Actor#call) method. This method has an optional `logger` argument, which is by default set to `default` literal. This means that the logs of the called Actor will be automatically redirected to the parent Actor's logs with default formating and filtering. If you set `logger` argument to `None`, then no log redirection happens. Third option is to pass your own `Logger` instance with the possibility to define own formater, filter and handler.
93+
Typical use case for log redirection is to call another Actor using the [`Actor.call`](../../reference/class/Actor#call) method. This method has an optional `logger` argument, which is by default set to `default` literal. This means that the logs of the called Actor will be automatically redirected to the parent Actor's logs with default formating and filtering. If you set `logger` argument to `None`, then no log redirection happens. Third option is to pass your own `Logger` instance with the possibility to define own formater, filter and handler. Below you can see those three possible ways of log redirection when starting another Actor run through [`Actor.call`](../../reference/class/Actor#call).
9494

9595
<CodeBlock className="language-python">
9696
{RedirectLog}
@@ -103,7 +103,10 @@ The log redirection can be deep, meaning that if the other actor also starts ano
103103
![Console with redirected logs](/img/guides/redirected_logs_example.png 'Example of console with redirected logs from recursively started actor.')
104104

105105
### Redirecting logs from already running Actor run
106-
In some cases you might want to connect to an already running Actor run and redirect its logs to your current Actor run. This can be done using the `ApifyClient` from `apify-client-python` directly.
106+
In some cases you might want to connect to an already running Actor run and redirect its logs to your current Actor run. This can be done using the [ApifyClient](../../reference/class/Actor#apify_client) and getting the streamed log from a specific Actor run. You can then use it as a context manager and the log redirection will be active in the context, or you can control the log redirection manually by explicitly calling `start` and `stop` methods.
107+
108+
You can further decide whether you want to redirect just new logs of the ongoing Actor run or if you also want to redirect historical logs from that actor run - so all logs it has produced since it was started. Both options are shown in the example code below.
109+
107110
<CodeBlock className="language-python">
108111
{RedirectLogExistingRun}
109112
</CodeBlock>

docs/03_concepts/code/10_redirect_log_existing_run.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55

66
async def main() -> None:
77
async with Actor:
8-
# With context manager
9-
async with await Actor.new_client().run('some_actor_id').get_streamed_log():
8+
# Lifecycle of redirected logs is handled by the context manager.
9+
async with await Actor.apify_client.run('some_actor_id').get_streamed_log(
10+
# Redirect all logs from the start of that run, even the logs from past.
11+
from_start=True
12+
):
1013
await asyncio.sleep(5)
1114
# Logging will stop out of context
1215

13-
# With direct call (lifecycle of logging has to be manually handled)
14-
streamed_log = await Actor.new_client().run('some_id').get_streamed_log()
16+
# Lifecycle of redirected logs can be handled manually.
17+
streamed_log = await Actor.apify_client.run('some_id').get_streamed_log(
18+
# Do not redirect historical logs from this actor run.
19+
# Redirect only new logs from now on.
20+
from_start=False
21+
)
1522
streamed_log.start()
1623
await asyncio.sleep(5)
1724
await streamed_log.stop()

0 commit comments

Comments
 (0)