Rust-Fblog v3.1.2: fblog — Small command-line JSON Log viewer

./logo/fblog_small.png

fblog

https://img.shields.io/crates/v/fblog.svg https://travis-ci.org/brocode/fblog.svg?branch=master

A small tool to view json log files.

demo.png

Filter

To filter log messages it is possible to use lua

fblog -f 'level ~= "info"' # will print all message where the level is not info
fblog -f 'process == "play"' # will print all message where the process is play
fblog -f 'string.find(fu, "bow.*") ~= nil' # will print all messages where fu starts with bow
fblog -f 'process == "play"' # will print all message where the process is play
fblog -f 'process == "rust" and fu == "bower"'
fblog --no-implicit-filter-return-statement -f 'if 3 > 2 then return true else return false end'

# not valid lua identifiers
fblog -d -f '_G["log.level"] == "WARN"' sample_elastic.log

Customize

fblog tries to detect the message, severity and timestamp of a log entry. This behavior can be customized. See --help for more information.

You can customize fblog messages: Format output:

fblog -p --main-line-format "{{#if short_message}}{{ red short_message }}{{/if}}" sample.json.log

The following sanitized variables are provided by fblog:

  • fblog_timestamp
  • fblog_level
  • fblog_message
  • fblog_prefix

For the default formatting see --help

handlebar helpers:

  • bold
  • yellow
  • red
  • blue
  • purple
  • green
  • color_rgb 0 0 0
  • uppercase
  • level_style
  • fixed_size 10

NO_COLOR

fblog disables color output if the NO_COLOR environment variable is present.

no-color

Installation

cargo install fblog

If you need a deb or rpm package have a look at fblog releases

If you’re lucky enough to be an arch linux user: AUR

Comments

  • There is an issue with key-value additional fields
    There is an issue with key-value additional fields

    Nov 8, 2021

    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.

    enhancement 
    Reply
  • bump formula to newest version
    bump formula to newest version

    Dec 10, 2021

    @ChristianLohmann

                                                                                                                                                                                                            help wanted 
    Reply
  • no-color compliant
    no-color compliant

    Mar 3, 2020

    Would you consider implementing no-color?

    I could create a PR if you did.

    I ran into this while trying to pipe fblog output through less and getting something not as friendly

    ESC[1m2020-03-02T22:45:22ESC[0m ESC[1;31mERROR:ESC[0m Failed to send sms
    ESC[1;38;2;150;150;150m                     body:ESC[0m ID: 19169 Status: 1
    ESC[1;38;2;150;150;150m                     file:ESC[0m my/path/file.go:194
    ESC[1;38;2;150;150;150m                     func:ESC[0m other/path.monitorMsgID
    ESC[1;38;2;150;150;150m                    level:ESC[0m error
    ESC[1;38;2;150;150;150m                      msg:ESC[0m Failed to send sms
    ESC[1;38;2;150;150;150m                  request:ESC[0m http://localhost/query
    ESC[1;38;2;150;150;150m                     time:ESC[0m 2020-03-02T22:45:22Z
    ESC[1m2020-03-02T22:45:22ESC[0m ESC[1;31mERROR:ESC[0m Failed to send sms
    ESC[1;38;2;150;150;150m                    error:ESC[0m [{other/path/file.go:103: } {other/path/file.go:190: Failed to send sms}]
    ESC[1;38;2;150;150;150m                     file:ESC[0m my/path/file.go:106
    ESC[1;38;2;150;150;150m                     func:ESC[0m other/path.(*smsClient).Send
    ESC[1;38;2;150;150;150m                    level:ESC[0m error
    ESC[1;38;2;150;150;150m                      msg:ESC[0m Failed to send sms```
    enhancement 
    Reply
  • Allow reading from file or stdin.
    Allow reading from file or stdin.

    Feb 8, 2018

    Defaults to stdin if no filename given. also allows - for stdin.

    Reply
  • Support fields with other types than string.
    Support fields with other types than string.

    Sep 18, 2020

    Sometime fblog does not parse number values(but sometime do).

    $ cat > x.json
    {"timestamp":"2020-09-17 07:11:54.936","@version":"1","message":"Done Good!. exitCode: 0","thread":"main","level":"INFO","caller_file_name":"MyApplication.java","caller_line_number":12345}
    
    $ cat x.json | .cargo/bin/fblog --main-line-format "{{fblog_timestamp}} {{level_style fblog_level}} [{{thread}}] ({{caller_file_name}}#{{caller_line_number}}) {{fblog_message}}"
    
    # there is no number 12345
    2020-09-17 07:11:54.936 INFO [main] (MyApplication.java#) Done Good!. exitCode: 0
    
    # the result I expected
    2020-09-17 07:11:54.936 INFO [main] (MyApplication.java#12345) Done Good!. exitCode: 0
    
    enhancement 
    Reply
  • Provide precompiled binary
    Provide precompiled binary

    Nov 4, 2021

    null

                                                                                                                                                                                                            enhancement 
    Reply
  • pretty printed json seems to be an issue
    pretty printed json seems to be an issue

    May 5, 2021

    I have a json file that I have to pre-process via jq after that run I end up in pretty printed (multiline) json. Feeding this into fblog causes some strange errors, example below:

    the json fed into fblog looks like (excerpt):

    {
      "@message": "[object Object]\nResponse Headers have already been sent",
      "@timestamp": "2021-05-05T11:00:42.627Z",
      "@fields": {
        "level": "error"
      }
    }
    {
      "@message": "[object Object]\nResponse Headers have already been sent",
      "@timestamp": "2021-05-05T11:01:13.650Z",
      "@fields": {
        "level": "error"
      }
    }
    

    This very json ends up like this:

    $ cat *json* | grep -v 'info' | grep -v 'debug' | jq '.log | fromjson ' | fblog
    
    ??? > {
    ??? >   "@message": "[object Object]\nResponse Headers have already been sent",
    ??? >   "@timestamp": "2021-05-05T11:00:42.627Z",
    ??? >   "@fields": {
    ??? >     "level": "error"
    ??? >   }
    ??? > }
    ??? > {
    ??? >   "@message": "[object Object]\nResponse Headers have already been sent",
    ??? >   "@timestamp": "2021-05-05T11:01:13.650Z",
    ??? >   "@fields": {
    ??? >     "level": "error"
    ??? >   }
    ??? > }
    

    besides the json keys not fitting the default of fblog (that can be fixed via -l | -m | -t) the whole multiline json topic seems to be the root cause.

    Does fblog expect single line json?

    Reply
  • messages are HTML escaped.
    messages are HTML escaped.

    Sep 17, 2020

    Whe I use fblog - https://github.com/brocode/fblog/releases/download/v2.1.0/fblog.deb deb packaged version, It works greatly.

    But if I install with cargo install fblog, fblog print HTML escaped message.

    What's the difference?

    bug 
    Reply
  • support log tailing
    support log tailing

    Dec 16, 2021

    Please

    • support tailing logs (reading forever)
    • support starting from the end (for tailing)
    Reply
  • Support nested fields
    Support nested fields

    Sep 18, 2020

    Currently only toplevel keys are processed.

    enhancement 
    Reply
  • thread 'main' panicked at 'Expect to be able to write to out stream.'
    thread 'main' panicked at 'Expect to be able to write to out stream.'

    Apr 30, 2020

    Sorry to bother you again. This happens when you pipe to less and then quit, like so (bash):

    > fblog -d huge-log.json | less -r
    # now press `:q` to quit less
    thread 'main' panicked at 'Expect to be able to write to out stream.: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }', src/log.rs:100:7
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    I don't think that it's a problem, but it doesn't look nice.

    enhancement 
    Reply
  • RFE: Customizable core fields & layout
    RFE: Customizable core fields & layout

    Feb 25, 2020

    I like the idea that for each log event fblog displays a main line and optional additional lines per field. However, succinctness is also a virtue. Three lines to display message + logger name + thread name is a significant waste of vertical space. Thus, I had like to be able to cram more info into the main line.

    jaslog, a similar project, includes logger and thread name, https://github.com/jbruggem/jaslog/blob/master/src/line_formats.rs#L76. It seems a reasonable decision, but I imagine that essential fields are context dependent and every user has its personal opinion about what to display in the main line.

    Would it make sense to:

    1. Add more fields to the main line
    2. Provide a configuration mechanism to decide what, and perhaps how, to display in the main line
    enhancement 
    Reply