Categorygithub.com/libgo/logx
modulepackage
1.0.5
Repository: https://github.com/libgo/logx.git
Documentation: pkg.go.dev

# README

env

LOGX_GLOBAL_LEVEL

LOGX_REDIS_DSN
LOGX_REDIS_KEY
LOGX_REDIS_LEVEL
LOGX_REDIS_ASYNC

LOGX_FILE_NAME
LOGX_FILE_FORMAT
LOGX_FILE_LEVEL
LOGX_FILE_ASYNC
LOGX_FILE_MAXSIZE
LOGX_FILE_MAXAGE
LOGX_FILE_MAXBACKUPS
LOGX_FILE_LOCALTIME
LOGX_FILE_COMPRESS

LOGX_STD_ON
LOGX_STD_LEVEL
LOGX_STD_ASYNC
package main

import (
	"errors"
	"os"

	"github.com/libgo/logx"
)

func main() {
	// global kv, NOT thread safe
	logx.SetAttach(map[string]interface{}{
		"svc":  "test",
		"mode": "dev",
	})

	// global output
	logx.SetOutput(os.Stdout)

	// multi output with different level
	logx.SetOutput(logx.RedisWriter(logx.RedisConfig{
		DSN:    "redis://:@127.0.0.1:6379",
		LogKey: "log:test",
		Level:  InfoLevel,
		Async:  true,
	}), logx.StdWriter(logx.StdConfig{Level: DebugLevel}))

	// global level
	logx.SetGlobalLevel(logx.InfoLevel)

	logx.Debug("hello")

	err := errors.New("some error")
	logx.Caller().Error(err)

	logger := logx.Logger()
	logger.Info("hello world")
}

go test -v . -test.bench=".*"

goos: darwin
goarch: amd64
pkg: github.com/libgo/logx
BenchmarkBase-8     	300000000	         5.96 ns/op	       0 B/op	       0 allocs/op
BenchmarkDebug-8    	50000000	        36.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkDebugf-8   	50000000	        30.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkKV-8       	20000000	        84.2 ns/op	      16 B/op	       1 allocs/op
BenchmarkSetKV-8    	30000000	        55.6 ns/op	      16 B/op	       1 allocs/op
PASS

# Functions

Attach add global kv to logger, this is NOT thread safe.
No description provided by the author
Close resource FILO.
No description provided by the author
No description provided by the author
No description provided by the author
Error v if error value, it will try print e.stack using special %_- as error stack.
No description provided by the author
Fatal v if error value, it will try print e.stack using special %_- as error stack.
No description provided by the author
FileWriter write log to file.
No description provided by the author
No description provided by the author
No description provided by the author
KV should be paired, and key should be string.
Deprecated KVPair need allocate for type convert, using KV instead.
Logger return *Log from pool.
NewAsyncWriter creates a writer wrapping w with a many-to-one diode in order to never block log producers and drop events if the writer can't keep up with the flow of data.
RedisWriter writer log to redis.
Deprecated, using Attach instead.
SetGlobalCaller set global caller status.
SetGlobalLevel set global log level.
SetOutput set multi log writer, all SetXXX method are non-thread safe.
No description provided by the author
No description provided by the author
StdWriter write log to console.
TakeStacktrace is helper func to take snap short of stack trace.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

Level.
Level.
Level.
Level.
Level.
Level.
Level.

# Structs

Writer is a io.Writer wrapper that uses a diode to make Write lock-free, non-blocking and thread safe.
FileConfig is conf for file writer.
No description provided by the author
RedisConfig is conf for redis writer.
StdConfig is conf for console std writer.

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
zerolog type alias.