-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add debug/1 to log debug messages without consuming stdin #2478
Conversation
2142d54
to
ab5c5b0
Compare
ab5c5b0
to
3630990
Compare
8359b61
to
d7f69ea
Compare
Define `debug/1` to call `debug/0`, but send `stdin` to `stdout` without consuming it, while printing the debug messages to `stderr`. Example usage: ```sh seq 2 | LOG_LEVEL=DEBUG jq ' debug({$ENV}) | debug({line: input_line_number}) | debug("\(now | todate) here1: .=\(.)") | . * 10 | debug("\(now | todate) here2: .=\(.)") | . + 1 ' ``` => ``` ["DEBUG:",{"ENV":{"PWD":"/tmp","SHELL":"/bin/zsh","PATH":"/usr/bin:/bin", ...}}] ["DEBUG:",{"line":1}] ["DEBUG:","2022-09-03T10:52:24Z here1: .=1"] ["DEBUG:","2022-09-03T10:52:24Z here2: .=10"] 11 ["DEBUG:",{"ENV":{"PWD":"/tmp","SHELL":"/bin/zsh","PATH":"/usr/bin:/bin", ...}}] ["DEBUG:",{"line":2}] ["DEBUG:","2022-09-03T10:52:24Z here1: .=2"] ["DEBUG:","2022-09-03T10:52:24Z here2: .=20"] 21 ``` ie. a *slightly* less efficient way of achieving: ```sh seq 2 | jq ' . * 10 | . + 1 ' ``` => ``` 11 21 ```
d7f69ea
to
0273615
Compare
I appreciate your PR, since I have to define the same function for complex jq programs. |
@ck3d - yer I know - right? The manual currently just says:
Have you seen any mentions anywhere else, as to when or what it might change to? |
No, I have no idea. I am more an heavy user of jq not a developer. |
Actually @ck3d, |
When I need to debug stuff adding information to the debug message, I usually use: empty = ("something: \(.)" | debug) This works because the rhs of assignments other than the update assignment ( As a side note: here is an overload for def _assign(p;v):
. as $dot |
reduce ([ "o" ] + path(p)) as $p ({ o: . };
setpath($p; .v //= ($dot | [ v ]) | .v[])) |
.o;
|
@emanuele6 - Ahh brilliant, thanks for the explanation! I wonder if
|
Closed by #2710 |
Define
debug/1
to calldebug/0
, but sendstdin
tostdout
without consuming it,while printing the debug messages to
stderr
.Example usage:
=>
ie. a slightly less efficient way of achieving:
=>