fblog icon indicating copy to clipboard operation
fblog copied to clipboard

Print all fields of a nested json object

Open MeisQuietude opened this issue 4 years ago โ€ข 1 comments

Hi, thank you for the useful tool! I have an issue with using the flag "--additional-value".

I'm using fblog v3.0.2 built by myself using Cargo and source code.

The output of execute $ fblog --help:

fblog 3.0.2
Brocode inc <[email protected]>
json log viewer

USAGE:
    fblog [FLAGS] [OPTIONS] [--] [INPUT]

...

The problem is that the output does not contain the field I specified using the flag -a.

I have the log message:

{"time": "2021-11-08T13:55:45.924593+00:00", "level": "INFO", "caller": "/app/service/runner.py:58", "message": "Some message here", "process": "1", "thread": "MainThread", "function": "run", "line_no": "58", "module": "runner", "logger": "service.runner", "extra": {"a": 1}}

I want to see a value of the key "extra", so i'm using fblog -a extra and it doesn't work. At the same time, if I use the command fblog -a module, the value of the key module is displayed correctly.

Please help me figure out what I'm doing wrong, or confirm that this is a bug.

MeisQuietude avatar Nov 08 '21 14:11 MeisQuietude

This is a missing feature. You can use -a "extra > a" but there is no "wildcard" to select all nested fields.

bomgar avatar Nov 08 '21 14:11 bomgar

๐Ÿ‘‹ It might be that I have the same issue. I have the next line:

{"M":"msg","record":[{"aaa":"bbb"}]}

I tried cat json.log | fblog -a'record[1] > aaa' and cat json.log | fblog -a'record[1].aaa' No luck. Is it possible to display bbb? Or maybe it is possible to display the whole record as a string?

ezh avatar Nov 01 '22 07:11 ezh

Array selection is something that needs improvement. In general the approach to select specific fields needs a rework. I don't have the time at the moment but I'll look into it eventually. I know it is not good enough but I usually use -d in those cases.

bomgar avatar Nov 03 '22 10:11 bomgar

09:25:20 fblog is ๐Ÿ“ฆ v4.2.0 via ๐Ÿฆ€ v1.64.0 on ๎‚  master
ยป cat sample_nested.json.log
{"timestamp":"<>2017-07-06T15:21:16.378+00:00", "log": {"level": "info"}, "status": {"a": 100, "b": "te\nst", "c": true}, "message": "test"}
{"timestamp":"<>2017-07-06T15:21:16.378+00:00", "log": {"level": "info"}, "status": {"a": 200, "b": "sdfdsf", "c": true}, "message": "test"}
{"timestamp":"<>2017-07-06T15:21:16.378+00:00", "log": {"level": "info"}, "status": {"a": 200, "b": "sdfdsf", "c": true, "d": [{"a": 1}, [["a", "b"], [{"x": {"y": "a"}}]], "b"]}, "message": "test"}
09:27:45 fblog is ๐Ÿ“ฆ v4.2.0 via ๐Ÿฆ€ v1.64.0 on ๎‚  master
ยป fblog -d sample_nested.json.log
<>2017-07-06T15:21: UNKNO: test
              log > level: info
                  message: test
               status > a: 100
               status > b: te
st
               status > c: true
                timestamp: <>2017-07-06T15:21:16.378+00:00
<>2017-07-06T15:21: UNKNO: test
              log > level: info
                  message: test
               status > a: 200
               status > b: sdfdsf
               status > c: true
                timestamp: <>2017-07-06T15:21:16.378+00:00
<>2017-07-06T15:21: UNKNO: test
              log > level: info
                  message: test
               status > a: 200
               status > b: sdfdsf
               status > c: true
        status > d[1] > a: 1
      status > d[2][1][1]: "a"
      status > d[2][1][2]: "b"
status > d[2][2][1] > x >: a
            status > d[3]: "b"
                timestamp: <>2017-07-06T15:21:16.378+00:00
09:27:52 fblog is ๐Ÿ“ฆ v4.2.0 via ๐Ÿฆ€ v1.64.0 on ๎‚  master
ยป fblog -a status sample_nested.json.log
<>2017-07-06T15:21: UNKNO: test
               status > a: 100
               status > b: te
st
               status > c: true
<>2017-07-06T15:21: UNKNO: test
               status > a: 200
               status > b: sdfdsf
               status > c: true
<>2017-07-06T15:21: UNKNO: test
               status > a: 200
               status > b: sdfdsf
               status > c: true
        status > d[1] > a: 1
      status > d[2][1][1]: "a"
      status > d[2][1][2]: "b"
status > d[2][2][1] > x >: a
            status > d[3]: "b"
09:27:57 fblog is ๐Ÿ“ฆ v4.2.0 via ๐Ÿฆ€ v1.64.0 on ๎‚  master
ยป fblog -a 'status > d[1] > a' sample_nested.json.log
<>2017-07-06T15:21: UNKNO: test
<>2017-07-06T15:21: UNKNO: test
<>2017-07-06T15:21: UNKNO: test
        status > d[1] > a: 1
        ```

bomgar avatar Nov 11 '22 08:11 bomgar

It is not perfect but is now supports both use cases.

-a status prints the entire status object and -a 'status > d[1] > a' selects something inside an array.

bomgar avatar Nov 11 '22 08:11 bomgar