Giter Site home page Giter Site logo

fhopfensperger / json-log-to-human-readable Goto Github PK

View Code? Open in Web Editor NEW
5.0 0.0 1.0 164 KB

A tool to convert JSON log messages to a human-readable format.

License: Apache License 2.0

Go 83.79% Shell 14.32% Dockerfile 1.89%
human-readable json kubernetes log logging

json-log-to-human-readable's Introduction

json-log-to-human-readable

Go Go Report Card Coverage Status Release

Convert JSON log messages to a human-readable format.

The following formats are supported:

Flags:
  -d, --dotnet       .NET JSON input
  -h, --help         help for json-log-to-human-readable
  -s, --springboot   Spring Boot JSON input
  -v, --version      version for json-log-to-human-readable
  -z, --zap          Uber zap JSON Input

Usage Examples:

test.json
{ "level": "INFO", "timestamp": "2020-07-14T09:38:14.977Z", "message": "sample output", "loggerName": "org.acme.MyClass" }
cat test.json | json-log-to-human-readable
Output
INFO 2020-07-14T09:38:14.977Z    org.acme.MyClass       sample output

This also works for Pods running in Kubernetes:

kubectl logs -f pod1 | json-log-to-human-readable

Spring Boot JSON Logging format could be transformed with -s

test-spring-boot.json
{"@timestamp":"2020-07-15T19:09:39.983Z","@version":"1","message":"My log message","logger_name":"org.acme.MyClass","thread_name":"pool-1-thread-1","level":"INFO","level_value":20000}
cat test-spring-boot.json |  json-log-to-human-readable -s
Output
INFO 2020-07-15T19:09:39.983Z    org.acme.MyClass       My log message

Uber Zap JSON Logging format could be transformed with -z

test-uber-zap.json
{"level":"error","ts":1598445905.143377,"logger":"controller-runtime.controller","msg":"Reconciler error","controller":"scaledobject-controller","request":"default/azure-servicebus-queue-scaledobject","error":"error getting scaler for trigger #0: error parsing azure service bus metadata: no connection setting given","stacktrace":"github.com/go-logr/zapr.(*zapLogger).Error\n\t/Users/zroubali/go/pkg/mod/github.com/go-logr/[email protected]/zapr.go:128\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/Users/zroubali/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:218\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/Users/zroubali/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:192\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).worker\n\t/Users/zroubali/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:171\nk8s.io/apimachinery/pkg/util/wait.JitterUntil.func1\n\t/Users/zroubali/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:152\nk8s.io/apimachinery/pkg/util/wait.JitterUntil\n\t/Users/zroubali/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:153\nk8s.io/apimachinery/pkg/util/wait.Until\n\t/Users/zroubali/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:88"}
cat test-uber-zap.json |  json-log-to-human-readable -z
Output
error 2020-08-26 14:45:05.143377065 +0200 CEST   controller-runtime.controller  msg: Reconciler error   controller: scaledobject-controller      request: ugsvt-mercedes/azure-servicebus-queue-scaledobject
error: error getting scaler for trigger #0: error parsing azure service bus metadata: no connection setting givenstacktrace: github.com/go-logr/zapr.(*zapLogger).Error
        /Users/zroubali/go/pkg/mod/github.com/go-logr/[email protected]/zapr.go:128
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
        /Users/zroubali/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:218
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
        /Users/zroubali/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:192
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).worker
        /Users/zroubali/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:171
k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1
        /Users/zroubali/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:152
k8s.io/apimachinery/pkg/util/wait.JitterUntil
        /Users/zroubali/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:153
k8s.io/apimachinery/pkg/util/wait.Until
        /Users/zroubali/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:88

Installation

Homebrew

brew install fhopfensperger/tap/json-log-to-human-readable

Script

curl https://raw.githubusercontent.com/fhopfensperger/json-log-to-human-readable/master/get.sh | bash

Manually

Go to Releases download the latest release according to your processor architecture and operating system, then unarchive and copy it to the right location

tar xvfz json-log-to-human-readable_x.x.x_darwin_amd64.tar.gz
cd json-log-to-human-readable_x.x.x_darwin_amd64
chmod +x json-log-to-human-readable
sudo mv json-log-to-human-readable /usr/local/bin/

Run as container

Besides installing the binary on the local computer, you have the option to run the program as a container

kubectl logs -f pod1 | docker run -i ghcr.io/fhopfensperger/json-log-to-human-readable

json-log-to-human-readable's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar fhopfensperger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Forkers

svngpsk

json-log-to-human-readable's Issues

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/fhopfensperger/json-log-to-human-readable/cmd: cannot find module providing package github.com/fhopfensperger/json-log-to-human-readable/cmd

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

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.