Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

kumoly.io/lib/klog

Package Overview
Dependencies
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kumoly.io/lib/klog

Go Modules
Version
v0.0.8
Version published
Created
Source

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

v0.0.5
go test -bench . -run none --benchmem
goos: linux
goarch: amd64
pkg: kumoly.io/lib/klog
cpu: AMD Ryzen 9 5900X 12-Core Processor            
BenchmarkDefault-12                25216             47204 ns/op           20953 B/op        291 allocs/op
BenchmarkSub1-12                   22789             52306 ns/op           21719 B/op        351 allocs/op
BenchmarkStackSTD-12              105280             11347 ns/op            3596 B/op         26 allocs/op
BenchmarkStackSTDStr-12           234535              5109 ns/op            2755 B/op         27 allocs/op
BenchmarkStackCust-12              14764             80228 ns/op          171553 B/op         60 allocs/op
BenchmarkStackCustStr-12           15417             78187 ns/op          171262 B/op         61 allocs/op

v0.0.8
go test -bench . -run none --benchmem
goos: linux
goarch: amd64
pkg: kumoly.io/lib/klog
cpu: AMD Ryzen 9 5900X 12-Core Processor            
BenchmarkDefault-12                41521             28847 ns/op           13488 B/op        209 allocs/op
BenchmarkSub1-12                   37726             31813 ns/op           14256 B/op        269 allocs/op
BenchmarkStackSTD-12              119014             10006 ns/op            3308 B/op         19 allocs/op
BenchmarkStackSTDStr-12           306621              3798 ns/op            2466 B/op         20 allocs/op
BenchmarkStackCust-12              16908             71334 ns/op          170968 B/op         54 allocs/op
BenchmarkStackCustStr-12           16702             70945 ns/op          170969 B/op         54 allocs/op

FAQs

Package last updated on 10 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts