logdna / logdna-cli

The LogDNA CLI allows you to signup for a new account and tail your server logs right from the command line.
https://logdna.com
MIT License
27 stars 21 forks source link

Enable option to get truly raw output in searches #42

Closed pratikmallya closed 4 years ago

pratikmallya commented 4 years ago

Currently, when attempting to do a search, the first line summarizes the findings:

logdna search "QUERY" -j
search finished: 5 line(s). hosts: all. apps: all. levels: all. tags: all. query: QUERY

This makes it hard to use the cli as part of unix pipelines. e.g. I would like to use jq to parse the logs into a more human friendly log, but that's not possible (well it is if one uses tail e.g. logdna search "QUERY" -j | tail -n +2| jq .)

To be effective as a cli tool, I would expect the raw json output to give a truly raw json response so tail does not have to be used.

andkon commented 4 years ago

Thanks @pratikmallya. Just to help me understand your use case – if you don't put in the -n +2 flag to tail, will jq blow up?

pratikmallya commented 4 years ago

if you don't put in the -n +2 flag to tail, will jq blow up?

Yep:

logdna search "QUERY" -j | jq
parse error: Invalid numeric literal at line 1, column 7
joshk0 commented 4 years ago

A typical recourse here is to send the informational output to stderr while the core output remains on stdout. This is what things like curl and tar do.

navyapothineni commented 4 years ago

To chime in, occasionally I've seen 0 logs returned on some search queries. For which the empty result message is also output to stdout. It'd be good to have a separate exit code and the msg to stderr for such cases when using the raw json option.

search finished: 0 line(s). hosts: all. apps: all. levels: all. tags: all. query: <some-query>
Query returned no lines.
andkon commented 4 years ago

This is great feedback – thanks @joshk0 and @navyapothineni. Sitting down today to hash out an appropriate solution.

ghost commented 4 years ago

Thanks. PR #43 will close this issue.

smusali commented 4 years ago

@pratikmallya, this has been added/fixed in the newest v2 release which is available to be used. Please, let us know if you have any other additional comments!