lvlog

package module
v0.0.0-...-3402eef Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: MIT Imports: 3 Imported by: 8

README

lvlog

Standard logger with levels. Uses log package internally, doesn't create its own logger instance, so it's possible to share flags etc. with std logger

usage

Can be used as a drop-in replacement for standard "log" package, as seen below. For details see source code, it's simple enough.


import log "github.com/ppp225/lvlog"

func main() {
	log.Info("info msg")              // == std.Println(" [INFO]", "info msg")
	log.Infof("msg=%q", "info msg")   // == std.Printf("%s msg=%q", " [INFO]", "info msg")
	log.Debug("debug msg")            // won't be displayed
	log.SetLevel(log.ALL)             // default level is INFO and up
	log.Debug("debug msg")            // will be displayed now
	log.Fatalf("msg=%q", "fatal msg") // will be displayed and exit with status code 1
}

benchmarks

Benchmark_Off_baseline-12    	1000000000	     0.284 ns/op	       0 B/op	       0 allocs/op
Benchmark_Off_naive-12       	1000000000	     0.268 ns/op	       0 B/op	       0 allocs/op
Benchmark_Off_lvlog-12       	1000000000	     0.950 ns/op	       0 B/op	       0 allocs/op
Benchmark_Print_std-12       	 2201851	       526 ns/op	      48 B/op	       1 allocs/op
Benchmark_Print_lvlog-12     	 1646030	       826 ns/op	      96 B/op	       3 allocs/op
Benchmark_Printf_std-12      	 1120405	      1024 ns/op	      48 B/op	       1 allocs/op
Benchmark_Printf_lvlog-12    	 1132267	      1017 ns/op	      48 B/op	       1 allocs/op

Documentation

Index

Constants

View Source
const (
	TRACE = uint8(1 << iota)
	DEBUG
	INFO
	WARN
	ERROR
	PANIC
	FATAL
	ALL  = uint8(TRACE | DEBUG | INFO | WARN | ERROR | PANIC | FATAL)
	NORM = uint8(INFO | WARN | ERROR | PANIC | FATAL)
	NONE = uint8(0x0)
)

representation of all statuses.

Variables

View Source
var (
	TraceLabel = "[TRACE]"
	DebugLabel = "[DEBUG]"
	InfoLabel  = " [INFO]"
	WarnLabel  = " [WARN]"
	ErrorLabel = "[ERROR]"
	PanicLabel = "[PANIC]"
	FatalLabel = "[FATAL]"
)

status labels. Feel free to change them.

Functions

func Debug

func Debug(v ...interface{})

func Debugf

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

func Error

func Error(v ...interface{})

func Errorf

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

func Fatal

func Fatal(v ...interface{})

func Fatalf

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

func Info

func Info(v ...interface{})

func Infof

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

func Panic

func Panic(v ...interface{})

func Panicf

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

func Print

func Print(v ...interface{})

Print is a wrapper of log package log.Print func Is INFO-level, prepends InfoLabel

func Printf

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

Printf is a wrapper of log package log.Printf func Is equivalent to lvlog.Infof(), prepends InfoLabel

func Println

func Println(v ...interface{})

Println is a wrapper of log package log.Println func Is equivalent to lvlog.Info(), prepends InfoLabel

func SetFlags

func SetFlags(flag int)

SetFlags sets the output flags for the standard logger. It is a wrapper of the log package log.SetFlags func

func SetLevel

func SetLevel(lvls uint8)

SetLevel to 'log.ALL' or 'log.NONE' or 'log.INFO | log.ERROR'

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger. It is a wrapper of the log package log.SetOutput func

func Trace

func Trace(v ...interface{})

func Tracef

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

func Warn

func Warn(v ...interface{})

func Warnf

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

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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