Giter VIP home page Giter VIP logo

prettylog's Introduction

Prettylog

Command line tool that displays JSON logs in a human-friendly format.

Prettylog

Installation

Go 1.17+:

go install github.com/globocom/prettylog@latest

Go 1.16 or older:

curl https://github.com/globocom/prettylog/raw/master/install.sh | sh

Prettylog will be installed to $GOPATH/bin. Make sure to add it to your PATH so you can run prettylog anywhere.

How it works

Prettylog parses log messages that contain an arbitrary number of fields and generates a nice output in the following format:

<TIMESTAMP> <LOGGER> <CALLER> <LEVEL> <MESSAGE> <FIELD1>=<VALUE> <FIELD2>=<VALUE> ...

Non-existent fields will be ignored and messages not encoded as JSON will be printed as is.

Usage

Simply pipe the stdout of an application that outputs structured log messages into prettylog:

app | prettylog

You might need to redirect stderr to stdout if the application doesn't log to the standard output:

app 2>&1 | prettylog

Configuration

You can configure how Prettylog works by creating a .prettylog.yml file either locally (per directory) or globally (in $HOME):

timestamp:
  key:     <string>
  visible: <bool>
  color:   <list of int>
  format:  <string>

logger:
  key:     <string>
  visible: <bool>
  padding: <int>
  color:   <list of int>

caller:
  key:     <string>
  visible: <bool>
  padding: <int>
  color:   <list of int>

level:
  key:     <string>
  visible: <bool>
  padding: <int>
  colors:
    debug: <list of int>
    info:  <list of int>
    warn:  <list of int>
    error: <list of int>
    fatal: <list of int>

message:
  key:     <string>
  padding: <int>
  color:   <list of int>

Each field has its own key and the following properties are available:

Name Description
key Field name.
visible Flag indicating whether the field will be printed.
padding Number of whitespaces that will be added to the right of the field.
color/colors Color attributes. Up to 3 values can be used (fg, bg and effects). More information here.
format (timestamp field only) Layout that will be used to print timestamp values. It must follow the rules of the time package.

Using with other tools

Prettylog can be used along with other command line tools. Just make sure no buffer is enabled. For instance, grep has a --line-buffered flag:

app | grep --line-buffered -v debug | prettylog

If the tool you want to use buffers its output and does not offer such a flag, you can try stdbuff.

prettylog's People

Contributors

chavao avatar dependabot[bot] avatar luiz-mai avatar mbenford avatar rafaelrubbioli avatar rafaelsq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prettylog's Issues

Fix "LOW" vulnerabilities found via huskyCI

Hey! I have just ran huskyCI and a few low vulnerabilities were found in prettylog. All of them are related to Errors unhandled:

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/main.go
[HUSKYCI][!] Line: 54
[HUSKYCI][!] Code: app.Run(os.Args)

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/main.go
[HUSKYCI][!] Line: 59
[HUSKYCI][!] Code: cli.ShowAppHelp(ctx)

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/prettifiers/default.go
[HUSKYCI][!] Line: 54
[HUSKYCI][!] Code: buffer.WriteString(value)

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/prettifiers/default.go
[HUSKYCI][!] Line: 55
[HUSKYCI][!] Code: buffer.WriteString(SEPARATOR)

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/prettifiers/default.go
[HUSKYCI][!] Line: 63
[HUSKYCI][!] Code: buffer.WriteString(color.Sprint(field[0]))

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/prettifiers/default.go
[HUSKYCI][!] Line: 65
[HUSKYCI][!] Code: buffer.WriteString(field[0])

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/prettifiers/default.go
[HUSKYCI][!] Line: 67
[HUSKYCI][!] Code: buffer.WriteString(FIELD_SEPARATOR)

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/prettifiers/default.go
[HUSKYCI][!] Line: 68
[HUSKYCI][!] Code: buffer.WriteString(field[1])

[HUSKYCI][!] Language: Go
[HUSKYCI][!] Tool: GoSec
[HUSKYCI][!] Severity: LOW
[HUSKYCI][!] Confidence: HIGH
[HUSKYCI][!] Details: Errors unhandled.
[HUSKYCI][!] File: /go/src/code/prettifiers/default.go
[HUSKYCI][!] Line: 69
[HUSKYCI][!] Code: buffer.WriteString(SEPARATOR)

[HUSKYCI][SUMMARY] Go -> huskyci/gosec:2.0.0
[HUSKYCI][SUMMARY] High: 0
[HUSKYCI][SUMMARY] Medium: 0
[HUSKYCI][SUMMARY] Low: 9

[HUSKYCI][SUMMARY] Total
[HUSKYCI][SUMMARY] High: 0
[HUSKYCI][SUMMARY] Medium: 0
[HUSKYCI][SUMMARY] Low: 9
[HUSKYCI][SUMMARY] NoSecHusky: 0

[HUSKYCI][*] Some LOW/INFO issues were found :|

Do you think it would be a good idea to consider them? Just let me know if you would like to receive a PR fixing these issues! ๐Ÿ™ƒ

Surround fields containing spaces with quotes

Field values containing spaces should be surrounded with quotes so it's clear they are one single unit. For instance:

field1=one field2=one two three

should render as

field1=one field2="one two three"

README.md in other language

Can I add a README.md translated to Brazilian Portuguese in the project? I open a PR with the file added.

Set up CircleCI configuration

We could use CircleCI to add stages to be run on every push made to the project. Starting with make test would be a good idea, what do you think? I could help with that. ๐Ÿผ

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.