Coder Social home page Coder Social logo

flash's Introduction

Go Report Card Coverage Status Build Status PkgGoDev

flash

Creates an opinionated zap logger.

Adapting it as a logr.Logger instance

Shall you at some point need to pass a logr.Logger instance in your code, e.g. while writing code that uses the Kubernetes client library etc., you can use go-logr/zapr to wrap the logger, as follows:

package main

import (
	"github.com/go-logr/zapr"
	"github.com/postfinance/flash"
)

func main() {
	l := flash.New()
	z := zapr.NewLogger(l.Desugar())
        z.V(0).Info("I'm a zap logger complying with logr.Logger interface !")
}

Logger Without Stacktrace

New Logger

Debug / Info / Error

2020-10-09T09:29:06.363+0200    INFO    test/main.go:26 message {"StackTrace": "off", "debug": false}
2020-10-09T09:29:06.364+0200    ERROR   test/main.go:27 message {"StackTrace": "off", "debug": false}

Enable Debug

Debug / Info / Error

2020-10-09T09:29:06.364+0200    DEBUG   test/main.go:33 message {"StackTrace": "off", "debug": true}
2020-10-09T09:29:06.364+0200    INFO    test/main.go:34 message {"StackTrace": "off", "debug": true}
2020-10-09T09:29:06.364+0200    ERROR   test/main.go:35 message {"StackTrace": "off", "debug": true}

Disable Debug

Debug / Info / Error

2020-10-09T09:29:06.364+0200    INFO    test/main.go:42 message {"StackTrace": "off", "debug": false}
2020-10-09T09:29:06.364+0200    ERROR   test/main.go:43 message {"StackTrace": "off", "debug": false}

Fatal

2020-10-09T09:29:06.364+0200    FATAL   test/main.go:47 message {"StackTrace": "on", "debug": false}
exit status 1

Logger With Stacktrace

New Logger

Debug / Info / Error

2020-10-09T09:29:11.889+0200    INFO    test/main.go:26 message {"StackTrace": "off", "debug": false}
2020-10-09T09:29:11.889+0200    ERROR   test/main.go:27 message {"StackTrace": "off", "debug": false}

Enable Debug (Stacktrace on Error or above)

Debug / Info / Error

2020-10-09T09:29:11.889+0200    DEBUG   test/main.go:33 message {"StackTrace": "off", "debug": true}
2020-10-09T09:29:11.889+0200    INFO    test/main.go:34 message {"StackTrace": "off", "debug": true}
2020-10-09T09:29:11.889+0200    ERROR   test/main.go:35 message {"StackTrace": "off", "debug": true}
main.main
        /export/home/sauterm/tmp/test/main.go:35
runtime.main
        /export/home/sauterm/.gimme/versions/go1.15.2.linux.amd64/src/runtime/proc.go:204

Disable Debug (Stacktrace on Fatal only)

Debug / Info / Error

2020-10-09T09:29:11.889+0200    INFO    test/main.go:42 message {"StackTrace": "off", "debug": false}
2020-10-09T09:29:11.889+0200    ERROR   test/main.go:43 message {"StackTrace": "off", "debug": false}

Fatal

2020-10-09T09:29:11.889+0200    FATAL   test/main.go:47 message {"StackTrace": "on", "debug": false}
main.main
        /export/home/sauterm/tmp/test/main.go:47
runtime.main
        /export/home/sauterm/.gimme/versions/go1.15.2.linux.amd64/src/runtime/proc.go:204
exit status 1

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.