Go to file
Evan Chen 915bb73e37 fix: miscoloring message 2021-11-05 23:46:06 +08:00
.gitignore perf: use single tmpl 2021-11-04 11:23:40 +08:00
README.md refact: remove color sub package; allow intercepting logging 2021-11-05 23:29:34 +08:00
color.go refact: remove color sub package; allow intercepting logging 2021-11-05 23:29:34 +08:00
go.mod rename to klog 2021-11-04 02:56:46 +08:00
go.sum update 2021-11-01 22:38:30 +08:00
log.go fix: miscoloring message 2021-11-05 23:46:06 +08:00
log_test.go refact: remove color sub package; allow intercepting logging 2021-11-05 23:29:34 +08:00
std.go refact: remove color sub package; allow intercepting logging 2021-11-05 23:29:34 +08:00
util.go refat: use Fprintf over text/template 2021-11-05 15:56:36 +08:00

README.md

Logging with color and format string

Usage

import (
    "kumoly.io/lib/klog"
)

func main() {
    Lklog.EVEL = Lerror | Ldebug | Lwarn | Linfo
	klog.PROD = false
    klog.Info("Hello, world.")
    klog.Error("Error, world.")

    // create sub logger
    log := klog.Sub("me")
    log.Warn("log with me")

    // print fields
    log.InfoF(klog.H{"Key":"value"}, "other ", "stuffs.")

    // intercepting logs
    p := log.GetPrinter()
	log.SetPrinter(func(w io.Writer, d *Ldata, l *Logger) {
		d.Message += " intercepted"

        // NOT IN HERE
        // as it will cause infinate loop
        // p := log.GetPrinter()
		
        p(w, d, l)
	})

    
}

Test

Mem: go test -o tests/test.exe -memprofile tests/mem && go tool pprof -http : tests/mem Cpu: go test -o tests/test.exe -cpuprofile tests/cpu && go tool pprof -http : tests/cpu

Bench

go test -bench . -run none --benchmem
v0.0.1
BenchmarkDefault-8          8512            158272 ns/op
BenchmarkSub1-8             6140            166344 ns/op
BenchmarkDefault-8          6190            189078 ns/op           19522 B/op        387 allocs/op
BenchmarkSub1-8             6222            200761 ns/op           20511 B/op        435 allocs/op

go test -bench . -run none --benchmem
test(v0.0.2)
BenchmarkDefault-8         12410            109143 ns/op
BenchmarkSub1-8            10000            113340 ns/op
BenchmarkDefault-8         12186            112974 ns/op           21944 B/op        303 allocs/op
BenchmarkSub1-8            10000            114026 ns/op           22702 B/op        363 allocs/op

v0.0.4
goos: linux
goarch: amd64
pkg: kumoly.io/lib/klog
cpu: AMD Ryzen 9 5900X 12-Core Processor            
BenchmarkDefault-12        24697             47673 ns/op           21337 B/op        291 allocs/op
BenchmarkSub1-12           22639             52841 ns/op           22103 B/op        351 allocs/op