xlog

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ldate         = log.Ldate
	Ltime         = log.Ltime
	Lmicroseconds = log.Lmicroseconds
	Llongfile     = log.Llongfile
	Lshortfile    = log.Lshortfile
	Lmodule       = log.Lmodule
	Llevel        = log.Llevel
	LstdFlags     = log.LstdFlags
	Ldefault      = log.Ldefault
)
View Source
const (
	Ldebug = log.Ldebug
	Linfo  = log.Linfo
	Lwarn  = log.Lwarn
	Lerror = log.Lerror
	Lpanic = log.Lpanic
	Lfatal = log.Lfatal
)

Variables

View Source
var ForceSpawnCtx bool
View Source
var UseReqCtx bool

Functions

func Debug

func Debug(reqId string, v ...interface{})

func Debugf

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

func Error

func Error(reqId string, v ...interface{})

func Errorf

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

func Fatal

func Fatal(reqId string, v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf

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

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func Fatalln

func Fatalln(reqId string, v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func GenReqId

func GenReqId() string

func Info

func Info(reqId string, v ...interface{})

func Infof

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

func NewContext

func NewContext(ctx Context, xl *Logger) Context

func NewContextWith

func NewContextWith(ctx Context, a interface{}) Context

Born a context with:

  1. provided req id (if @a is reqIder)
  2. provided header (if @a is header)
  3. **DUMMY** trace recorder (if @a cannot record)

func NewContextWithRW

func NewContextWithRW(ctx Context, w http.ResponseWriter, r *http.Request) Context

func NewContextWithReq

func NewContextWithReq(ctx Context, req *http.Request) Context

func Panic

func Panic(reqId string, v ...interface{})

Panic is equivalent to Print() followed by a call to panic().

func Panicf

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

Panicf is equivalent to Printf() followed by a call to panic().

func Panicln

func Panicln(reqId string, v ...interface{})

Panicln is equivalent to Println() followed by a call to panic().

func SetFlags

func SetFlags(flag int)

func SetGenReqId

func SetGenReqId(f func() string)

func SetOutput

func SetOutput(w io.Writer)

func SetOutputLevel

func SetOutputLevel(lvl int)

func SingleStack

func SingleStack(reqId string, v ...interface{})

func Stack

func Stack(reqId string, v ...interface{})

func Warn

func Warn(reqId string, v ...interface{})

func Warnf

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

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx Context) (xl *Logger, ok bool)

func FromContextSafe

func FromContextSafe(ctx Context) (xl *Logger)

func New

func New(w http.ResponseWriter, req *http.Request) *Logger

func NewDummy

func NewDummy() *Logger

Born a logger with:

  1. new random req id
  2. **DUMMY** trace recorder (will not record anything)

func NewDummyWithCtx

func NewDummyWithCtx(ctx context.Context) *Logger

Born a logger with:

  1. new random req id
  2. provided ctx
  3. **DUMMY** trace recorder (will not record anything)

func NewWith

func NewWith(a interface{}) *Logger

Born a logger with:

  1. provided req id (if @a is reqIder)
  2. provided header (if @a is header)
  3. provided context (if @a is contexter)
  4. **DUMMY** trace recorder (if @a cannot record)

func NewWithReq

func NewWithReq(req *http.Request) *Logger

func (*Logger) Context

func (xlog *Logger) Context() context.Context

func (*Logger) CtxWithValue

func (xlog *Logger) CtxWithValue(key, value interface{}) context.Context

func (*Logger) Debug

func (xlog *Logger) Debug(v ...interface{})

func (*Logger) Debugf

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

func (*Logger) Error

func (xlog *Logger) Error(v ...interface{})

func (*Logger) Errorf

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

func (*Logger) Fatal

func (xlog *Logger) Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func (*Logger) Fatalf

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

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func (*Logger) Fatalln

func (xlog *Logger) Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func (*Logger) Header

func (xlog *Logger) Header() http.Header

func (*Logger) Info

func (xlog *Logger) Info(v ...interface{})

func (*Logger) Infof

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

func (*Logger) Panic

func (xlog *Logger) Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to panic().

func (*Logger) Panicf

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

Panicf is equivalent to Printf() followed by a call to panic().

func (*Logger) Panicln

func (xlog *Logger) Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to panic().

func (*Logger) Print

func (xlog *Logger) Print(v ...interface{})

Print calls Output to print to the standard Logger. Arguments are handled in the manner of fmt.Print.

func (*Logger) Printf

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

Printf calls Output to print to the standard Logger. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Println

func (xlog *Logger) Println(v ...interface{})

Println calls Output to print to the standard Logger. Arguments are handled in the manner of fmt.Println.

func (*Logger) ReqId

func (xlog *Logger) ReqId() string

func (*Logger) SingleStack

func (xlog *Logger) SingleStack(v ...interface{})

func (*Logger) Spawn

func (xlog *Logger) Spawn() *Logger

Spawn a child logger with:

  1. same req id with parent
  2. same trace recorder with parent(history compatibility consideration)
  3. a backgroud ctx, so when the xlog.ctx is done, the new xlog can continue 如果需要继承xlog 的生命周期,请使用 SpawnWithCtx

func (*Logger) SpawnWithCtx

func (xlog *Logger) SpawnWithCtx() *Logger

Spawn a child logger with:

  1. same req id with parent
  2. same trace recorder with parent(history compatibility consideration)
  3. same ctx with parent Warning: 调用这个方法,新的 routine 将会继承上游请求的生命周期——上游请求关闭,该 routine 也会关闭。 因此,一定要保证新的 routine 在主 routine 之前结束(可以考虑使用 waitgroup 来实现)。 此外,即使两个 routine 看似"同时"关闭,比如使用 multiwriter,也可能会产生问题,因为multiwriter 实际上还是有先后。

func (*Logger) Stack

func (xlog *Logger) Stack(v ...interface{})

func (*Logger) Warn

func (xlog *Logger) Warn(v ...interface{})

func (*Logger) Warnf

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

func (*Logger) WithContext

func (xlog *Logger) WithContext(ctx context.Context) *Logger

============================================================================ Warning: 仅限在少数特殊场合使用,返回的Logger和原来的Logger并不能并发调用! 返回一个只替换原先Logger的ctx的Logger

func (*Logger) Xbill

func (xlog *Logger) Xbill(key string, value interface{})

func (*Logger) Xget

func (xlog *Logger) Xget() []string

func (*Logger) XgetTag

func (xlog *Logger) XgetTag() []string

func (*Logger) Xlog

func (xlog *Logger) Xlog(v ...interface{})

func (*Logger) Xlogf

func (xlog *Logger) Xlogf(format string, v ...interface{})

func (*Logger) Xprof

func (xlog *Logger) Xprof(modFn string, start time.Time, err error)

* 用法示意:

func Foo(log xlog.*Logger) {
	...
	now := time.Now()
	err := longtimeOperation()
	log.Xprof("longtimeOperation", now, err)
	...
}

func (*Logger) Xprof2

func (xlog *Logger) Xprof2(modFn string, dur time.Duration, err error)

func (*Logger) Xput

func (xlog *Logger) Xput(logs []string)

func (*Logger) XputTag

func (xlog *Logger) XputTag(tags []string)

func (*Logger) Xtag

func (xlog *Logger) Xtag(v ...interface{})

func (*Logger) Xtrack

func (xlog *Logger) Xtrack(modFn string, start time.Time, errTrack *error)

* 用法示意:

func Foo(log xlog.*Logger) (err error) {
	defer log.Xtrack("Foo", time.Now(), &err)
	...
}

func Bar(log xlog.*Logger) {
	defer log.Xtrack("Bar", time.Now(), nil)
	...
}

func (*Logger) Xuid

func (xlog *Logger) Xuid(uid uint32)

Jump to

Keyboard shortcuts

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