Any way to detect the closing of stdout to disable the stdout sink? #87
-
Hi, I am writing a program that uses both the stdout and a file sink. The stdout sink is used for seeing the startup logging to make sure the program starts correctly (with the right config etc.) as well as monitoring things as it is running. The process is always started detached in the shell. However, once we are done monitoring we log out of our ssh session, thus closing the stdout stream. Which immediately makes the process panic on the next log printed to stdout. I am wondering if there is some way of detecting whether the stdout stream was closed so I can disable the stdout sink when that happens. Or is there perhaps a better way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @Ymif-Jordan, could you tell me the command you are using to start a detached program from shell? Which shell are you using? I'd like to reproduce the problem on my machine. |
Beta Was this translation helpful? Give feedback.
I have opened a PR #88 to fix the panic, could you test if it works for you?
However, in your case, each log will still do an absolute failure stdio write, which will have some performance overhead. And I suspect there's no clean way to detect broken stdio. If I were you, I would make a systemd service for this program and just do
systemctl status my-program
orjournalctl -ru my-program
to monitor its startup logging.