Say I have:
- a background task BT which may write to stderr
- a main task MT which may also write to stderr
I care about stderr from (MT) but not from (BT) and would like to hide things that come from (BT) as they’re unrelated (long standing HTTP issue…).
If that helps, I know the error messages that may happen on BT which would have to be hidden.
Toy example:
@sync begin
@spawn begin
for _ in 1:10
@error "I don't want to see this"
sleep(0.1)
end
end
@spawn begin
for _ in 1:10
@warn "I do want to see this"
@error "I also want to see this"
sleep(0.1)
end
end
end
I’m under the impression that redirect_stderr
is a global setting, so best I could try to think of is to have a redirect_stderr
for the whole @sync
block and somehow filter out what gets written to it on the fly but I’ve not been able to do this properly. For the toy code above, the following seems to work but I don’t think it’s generally correct:
@sync begin
bk_stderr = stderr
@spawn begin
for _ in 1:10
redirect_stderr()
@error "I don't want to see this"
sleep(0.1)
end
end
@spawn begin
for _ in 1:10
redirect_stderr(bk_stderr)
@warn "I do want to see this"
@error "I also want to see this"
sleep(0.1)
end
end
end
(of course it’d be easier if BT did not write to stderr in the first place, and this may happen, but in the meantime it’d be nice to have an alternative).