zlog

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

README

📝 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 perimeter is a common norm at Google (and many other tech giants). I'll start using context for logging when Google hires me 😄.

Documentation

Index

Constants

View Source
const ReqIDTag = "request_id"

ReqIDTag holds tag for request id

Variables

This section is empty.

Functions

func Debug

func Debug(msg string)

Debug prints a new message with debug level

func Debugf

func Debugf(format string, v ...interface{})

Debugf prints a new formatted message with debug level

func Error

func Error(msg string)

Error prints a new message with error level

func Errorf

func Errorf(format string, v ...interface{})

Errorf prints a new formatted message with error level

func Fatal

func Fatal(msg string)

Fatal prints a new message with fatal level and kills the system

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf prints a new formatted message with fatal level and kills the system

func GenReqID

func GenReqID(next http.Handler) http.Handler

GenReqID generates a new request id for each requests and stores in the gls. Storage is cleaned up after request is server.

func Info

func Info(msg string)

Info prints a new message with info level

func Infof

func Infof(format string, v ...interface{})

Infof prints a new formated message with info level

func Panic

func Panic(msg string)

Panic prints a new message with panic level and throws a panic

func Panicf

func Panicf(format string, v ...interface{})

Panicf prints a new formatted message with panic level and throws a panic

func Warn

func Warn(msg string)

Warn prints a new message with warn level

func Warnf

func Warnf(format string, v ...interface{})

Warnf prints a new formatted message with warn level

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL