DiscoFighter47 / zlog

Sugared logger for console with request id

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ“ zlog

You don't know what it's like, you don't have a clue
If you did you'd find yourselves doing the same thing too

Sugared logger for console with request id.


source: gopherize.me

πŸš₯ Disclaimer

This package heavily uses tylerb/gls as Goroutin Local Storage implementation which may not seem good practice to some.

πŸš€ Installation

go get github.com/DiscoFighter47/zlog

πŸ‘“ Examples

package main

import (
	"net/http"

	"github.com/DiscoFighter47/zlog"
)

func call() {
	zlog.Info("Hello Universe!")
}

func main() {
	http.Handle("/", zlog.GenReqID(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		zlog.Info("Hello World!")
		call()
	})))
	http.ListenAndServe(":3000", nil)
}

// Output: 2020-02-08T19:54:10+06:00 [info ] Hello World! request_id:92fb565f-3856-4a51-a0e9-744a5fad12fc
// Output: 2020-02-08T19:54:10+06:00 [info ] Hello Universe! request_id:92fb565f-3856-4a51-a0e9-744a5fad12fc

πŸ”“ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE.md file for details

❓ FAQ

  1. Why not just use context?
    Passing context as the first parameter is a common norm at Google (and many other tech giants). I'll start using context for logging when Google hires me πŸ˜„.

About

Sugared logger for console with request id

License:GNU General Public License v3.0


Languages

Language:Go 100.0%