Skip to content

DiscoFighter47/zlog

Repository files navigation

📝 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 😄.