Skip to content
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

[docs]fixing broken references, links, note #35694

Merged
merged 6 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
move customizing worker loggers from k8s to configure logging
Signed-off-by: angelinalg <[email protected]>
  • Loading branch information
angelinalg committed May 24, 2023
commit 0d8a0df972d07c56656952679e4f8c5dbbe47bd4
42 changes: 0 additions & 42 deletions doc/source/cluster/kubernetes/user-guides/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,48 +144,6 @@ kubectl logs raycluster-complete-logs-head-xxxxx -c fluentbit
[KubDoc]: https://kubernetes.io/docs/concepts/cluster-administration/logging/
[ConfigLink]: https://raw.githubusercontent.com/ray-project/ray/releases/2.4.0/doc/source/cluster/kubernetes/configs/ray-cluster.log.yaml

## Customizing Worker Loggers

When using Ray, all tasks and actors are executed remotely in Ray's worker processes.

:::{note}
To stream logs to a driver, they should be flushed to stdout and stderr.
:::

```python
import ray
import logging
# Initiate a driver.
ray.init()

@ray.remote
class Actor:
def __init__(self):
# Basic config automatically configures logs to
# be streamed to stdout and stderr.
# Set the severity to INFO so that info logs are printed to stdout.
logging.basicConfig(level=logging.INFO)

def log(self, msg):
logger = logging.getLogger(__name__)
logger.info(msg)

actor = Actor.remote()
ray.get(actor.log.remote("A log message for an actor."))

@ray.remote
def f(msg):
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info(msg)

ray.get(f.remote("A log message for a task."))
```

```bash
(Actor pid=179641) INFO:__main__:A log message for an actor.
(f pid=177572) INFO:__main__:A log message for a task.
```
## Using structured logging

The metadata of tasks or actors may be obtained by Ray's :ref:`runtime_context APIs <runtime-context-apis>`.
Expand Down
50 changes: 48 additions & 2 deletions doc/source/ray-observability/user-guides/configure-logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Configuring Logging
This guide helps you modify the default configuration of Ray's logging system.


Internal Ray Logging Configuration
Internal Ray logging configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When ``import ray`` is executed, Ray's logger is initialized, generating a sensible configuration given in ``python/ray/_private/log.py``. The default logging level is ``logging.INFO``.

Expand Down Expand Up @@ -40,7 +40,7 @@ Similarly, to modify the logging configuration for any Ray subcomponent, specify
# Here's how to add an aditional file handler for ray tune:
ray_tune_logger.addHandler(logging.FileHandler("extra_ray_tune_log.log"))

For more information about logging in workers, see :ref:`Customizing worker loggers`.
For more information about logging in workers, see :ref:`Customizing worker loggers <customize-worker-loggers>`.

Disabling logging to the driver
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -129,3 +129,49 @@ Limitations:

By default, the builtin print will also be patched to use `ray.experimental.tqdm_ray.safe_print` when `tqdm_ray` is used.
This avoids progress bar corruption on driver print statements. To disable this, set `RAY_TQDM_PATCH_PRINT=0`.

.. _customize-worker-loggers:

Customizing worker loggers
~~~~~~~~~~~~~~~~~~~~~~~~~~

When using Ray, all tasks and actors are executed remotely in Ray's worker processes.

.. note::

To stream logs to a driver, they should be flushed to stdout and stderr.

.. code-block:: python

import ray
import logging
# Initiate a driver.
ray.init()

@ray.remote
class Actor:
def __init__(self):
# Basic config automatically configures logs to
# be streamed to stdout and stderr.
# Set the severity to INFO so that info logs are printed to stdout.
logging.basicConfig(level=logging.INFO)

def log(self, msg):
logger = logging.getLogger(__name__)
logger.info(msg)

actor = Actor.remote()
ray.get(actor.log.remote("A log message for an actor."))

@ray.remote
def f(msg):
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info(msg)

ray.get(f.remote("A log message for a task."))

.. code-block:: bash

(Actor pid=179641) INFO:__main__:A log message for an actor.
(f pid=177572) INFO:__main__:A log message for a task.
Loading