json-log-viewer icon indicating copy to clipboard operation
json-log-viewer copied to clipboard

Read from pipe

Open LeNouveau opened this issue 6 years ago • 3 comments

Hi,

Would be nice to be able to pipe the input. Example of how I would like to use it :

docker logs 0e9fcbe6e5b2 -f | Select-String -Pattern "^{" | jv

Please notice the -f in docker's parameters. So, no need to re-run the command to refresh results.

Do you think it's possible ?

Regards, LeNouveau

LeNouveau avatar Nov 02 '18 12:11 LeNouveau

As a work around, what I do is to use a named-pipe on linux. Eg.

mkfifo jvfifo #need to do this once to create the fifo

then in one terminal

docker logs 0e9fcbe6e5b2 -f | Select-String -Pattern "^{" > jvfifo

and in another terminal window

jv jvfifo

Sadly I don't know of a way to do this on a Windows machine, Windows terminal support is worse than atrocious.

dieterrosch avatar May 30 '20 10:05 dieterrosch

Piping is the feature that will make this nice log viewer actually usable for me.

omidkrad avatar Jun 08 '21 04:06 omidkrad

As a work around, what I do is to use a named-pipe on linux. Eg.

mkfifo jvfifo #need to do this once to create the fifo

then in one terminal

docker logs 0e9fcbe6e5b2 -f | Select-String -Pattern "^{" > jvfifo

and in another terminal window

jv jvfifo

Sadly I don't know of a way to do this on a Windows machine, Windows terminal support is worse than atrocious.

Taking a look at the source code, unfortunately it looks like the log viewer loads the entire log file using readFileSync and converts it to a string, instead of using a buffer or a stream. In that case, if using a named-pipe of stdin for the input, the JSON log viewer would stall until stdin ends, which iirc doesn't happen until Ctrl+D.

We'd need to switch the readFileSync with a buffer/stream implementation.

Budgiebrain994 avatar Jul 05 '21 04:07 Budgiebrain994