Logger destination may be inconsistent - suggestion for a new Logger configuration field
The documentation specifies that
Benthos logging prints to stdout (or stderr if your output is stdout)
Unfortunately this doesn't work if the output uses a switch.
Benthos prints to stdout in this case, even if the selected case condition is stdout output.
To reproduce:
input:
generate:
mapping: |
root.id = count("foo_counter1")
interval: 0s
count: 3
output:
switch:
cases:
- check: false
output:
drop: {}
- output:
stdout:
codec: lines
This will print to stdout, but stderr is expected.
Also, considering the Logger doc:
Use these configuration options to change both the logging formats as well as the destination of logs.
A way of solving this issue could be to "force" the destination with a new field (destination? write_to?) in the Logger configuration.
Without too much reflection (especially about the file output), it could look to something like this:
logger:
level: INFO
format: logfmt
write_to: stderr # stdout | stderr | file?
Hey @krazylek, sounds like a neat addition, what's the particular use case you have? I would normally expect stdout to be used as an output in experimental/explorative situations.
Hi @Jeffail,
Yes actually my primary use case was for debugging: I used to pipe stdout to jq, which stopped working after having the switch in my output.
One thing I love with Benthos is the compatibility with unix streams and pipes: I know that whatever my needs, I can easily pipe the output to any unix tools: tail, head, grep and jq being the more common for me.
That's why when the logs were merged with stdout with the switch, I tried to find a way to keep this compatibility.
I guess another way to solve the issue would be to always output the logs to stderr, which is common in unix world. However I like the fact that one could decide where to write the logs: having them on stdout could also help with the debugging process or the monitoring! Especially when the data is directed to other services.