Coder Social home page Coder Social logo

jl's Introduction

jl - JSON Log Viewer GoDoc CircleCI

jl (JL) is a parser and formatter for JSON logs, making machine-readable JSON logs human readable again.

side-by-side-comparison

Installing

go get -u github.com/mightyguava/jl/cmd/jl

Usage

jl consumes from stdin and writes to stdout. To use jl, just pipe your JSON logs into jl. For example

./my-app-executable | jl
cat app-log.json | jl

jl can read from a file too

jl my-app-log.json

jl itself doesn't support following log files, but since it can consume from a pipe, you can just use tail

tail -F app-log.json | jl

you can page jl's colorized output using less with the -R flag

jl my-app-log.json | less -R

Formatters

jl currently supports 2 formatters, with plans to make the formatters customizable.

The default is -format compact, which extracts only important fields from the JSON log, like message, timestamp, level, colorizes and presents them in a easy to skim way. It drops un-recongized fields from the logs.

The other option is -format logfmt, which formats the JSON logs in a way that closely resembles logfmt. This option will emit all fields from each log line.

Both formatters will echo non-JSON log lines as-is.

Log formats

JSON application logs tend to have some core shared fields, like level, timestamp, and message that jq tries to discover and prioritize for formatting. For now, the following formats work best with jq. For string fields other than level, only the keys matter.

Java-like

{
  "level": "error",
  "timestamp": "2019-02-02 15:39:45",
  "logger": "HelloWorldService",
  "thread": "main",
  "message": "hello world",
  "exception": "java.lang.IllegalArgumentException: The world isn't here\n...stacktraces..."
}

See log_example.json for a more complete example.

Go/Logrus-like

{
  "level": "error",
  "timestamp": "2019-02-02 15:39:45",
  "msg": "hello world",
  "error": "hello error",
  "stack": "\nhello\n\thello.go\nworld\n\tworld.go"
}

Google Stackdriver

Stackdriver logs require a little pre-processing from jq.

gcloud logging read "resource.type=cloud_run_revision AND resource.labels.service_name=<YOUR_SERVICE>" --freshness=30m --format=json \
  | jq -c -r 'reverse | .[]' \
  | jl
{
  "insertId": "5e864b4c000cc26666c50a3b",
  "jsonPayload": {
    "message": "hello world",
    "foo": "bar"
  },
  "labels": {
    "instanceId": "..."
  },
  "logName": "projects/<PROJECT>/logs/run.googleapis.com%2Fstderr",
  "receiveTimestamp": "2020-04-02T20:30:05.116903175Z",
  "resource": {
    "labels": {
        "location": "...",
        "project_id": "...",
    },
    "type": "cloud_run_revision"
  },
  "severity": "INFO",
  "timestamp": "2020-04-02T20:30:04.835224670Z"
}

Roll your own format

If the format that JL provides does not suit your needs, All of jl's functionality is available as API, and it's simple to build your own CLI client. See the godocs for the API.

To change the compact format, all you need to do is provide another []FieldFmt specification

In the future, I plan to make jl configurable via either flags or config files, if there is demand for it.

jl's People

Contributors

mightyguava avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.