Skip to content

feat: Expose logger argument on Actor.call to control log redirection from started Actor run #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ keywords = [
"scraping",
]
dependencies = [
"apify-client>=1.9.2",
"apify-client>=1.11.0",
"apify-shared>=1.3.0",
"crawlee~=0.6.0",
"cryptography>=42.0.0",
Expand Down
5 changes: 5 additions & 0 deletions src/apify/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ async def call(
timeout: timedelta | None | Literal['RemainingTime'] = None,
webhooks: list[Webhook] | None = None,
wait: timedelta | None = None,
logger: logging.Logger | None | Literal['default'] = 'default',
) -> ActorRun | None:
"""Start an Actor on the Apify Platform and wait for it to finish before returning.

Expand All @@ -834,6 +835,9 @@ async def call(
a webhook set up for the Actor, you do not have to add it again here.
wait: The maximum number of seconds the server waits for the run to finish. If not provided,
waits indefinitely.
logger: Logger used to redirect logs from the Actor run. Using "default" literal means that a predefined
default logger will be used. Setting `None` will disable any log propagation. Passing custom logger
will redirect logs to the provided logger.

Returns:
Info about the started Actor run.
Expand Down Expand Up @@ -866,6 +870,7 @@ async def call(
timeout_secs=int(actor_call_timeout.total_seconds()) if actor_call_timeout is not None else None,
webhooks=serialized_webhooks,
wait_secs=int(wait.total_seconds()) if wait is not None else None,
logger=logger,
)

return ActorRun.model_validate(api_result)
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def prepare_test_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Callabl
"""

def _prepare_test_env() -> None:
delattr(apify._actor.Actor, '__wrapped__')
if hasattr(apify._actor.Actor, '__wrapped__'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very mysterious. Why did the previous implementation work on older Python versions and not in new ones (sometimes)?

delattr(apify._actor.Actor, '__wrapped__')
apify._actor._ActorType._is_any_instance_initialized = False

# Set the environment variable for the local storage directory to the temporary path.
Expand Down
11 changes: 6 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.