Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Define debug/1 in terms of debug/0
ie. so it can be used for logging debug messages. This modifies `debug` to `tee` the `stdin` to `stdout` without consuming it, while printing the debug messages to `stderr` if `LOG_LEVEL=DEBUG` is set in `$ENV`. Example usage: ``` seq 2 | LOG_LEVEL=DEBUG jq ' debug({$ENV}) | debug({line: input_line_number}) | debug("here1: .=\(.)") | . * 10 | debug("here2: .=\(.)") | . + 1 ' ``` => ``` ["DEBUG:",{"ENV":{"PWD":"/tmp","SHELL":"/bin/zsh","PATH":"/usr/bin:/bin", ...}}] ["DEBUG:",{"line":1}] ["DEBUG:","here1: .=1"] ["DEBUG:","here2: .=10"] 11 ["DEBUG:",{"ENV":{"PWD":"/tmp","SHELL":"/bin/zsh","PATH":"/usr/bin:/bin", ...}}] ["DEBUG:",{"line":2}] ["DEBUG:","here1: .=2"] ["DEBUG:","here2: .=20"] 21 ``` Or without `LOG_LEVEL=DEBUG`: ``` seq 2 | jq ' debug({$ENV}) | debug({line: input_line_number}) | debug("here1: .=\(.)") | . * 10 | debug("here2: .=\(.)") | . + 1 ' ``` => ``` 11 21 ```
- Loading branch information