question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Capturing and logging stdout/stderr on workers

See original GitHub issue

For various reasons, it is nice to be able to use stdout and stderr on workers and see the results. This can be useful in simplistic debugging attempts, using 3rd party code that already prints to one (or both) of these, etc. However it appears stdout and stderr are ignored in these settings currently.

A very useful feature would be to capture stdout and stderr on the worker and redirect them to a logger. One simple option would be to use the loggers distributed.worker.stdout and distributed.worker.stderr with info level messages. These loggers seem to be unused now and redirecting to them seems to work fine. This would at least give users one reasonable way to get this information.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:11
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
fjettercommented, Jun 1, 2022

In https://github.com/dask/distributed/pull/5217 (the ticket is a bit cryptic, below example pseudo code) we built a functionality to support “remote printing” that may be useful for some people in here. It appears we never updated the docs appropriately, at least I couldn’t find it.

from distributed import Client
from distributed.worker import print, warn

def func():
    print("foo")
c = Client("<ip_to_remote_scheduler>")
c.submit(func)

If you run a function on a remote worker and are using the distributed print function, it will print this message on stdout of your worker and forwards the message to the client and prints it on the client as well. The same works for warn as the stdlib warn works and you can build your own client handlers using Client.subscribe_topic in combination with Worker.log_event.

This obviously only scales to a certain level as was already pointed out with collecting logging information in a central place. At the very least the “simplistic debugging attempt” use case should be covered by this. For proper logging, I would not recommend using this.

2reactions
maxbanecommented, Oct 15, 2022

@ntonasa See my gist here for a proof-of-concept of how to use the subscribe mechanism that was added in #5217 to configure the forwarding of arbitrary logging statements by tasks running on workers to the client session.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get php-worker to log to stdout / stderr - Stack Overflow
It will show logs successfully, but I don't know why it works. So I write down the answer here for those who have...
Read more >
Capturing both stdout and stderr together in a log file
Write a small program that writes to both stdout and stderr: vim mini_program # file contents: echo "1 -- This is normal output"...
Read more >
Use "Redirect stdout/stderr logging enabled" checkbox in ...
Is it a good idea to check "Redirect stdout/stderr logging enabled" checkbox in Production OIM server?
Read more >
How to get php-fpm to log to stdout / stderr when running in a ...
Do some php-fpm config # Redirect worker stdout and stderr into main error log # Activate the fpm access log # Enable display...
Read more >
Kubernetes Logging: 101 Guide to Logs, Best Practices & More
Container logs are logs generated by your containerized applications. The easiest way to capture container logs is to use stdout and stderr ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found