Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(reqId string, v ...interface{})
- func Debugf(reqId string, format string, v ...interface{})
- func Error(reqId string, v ...interface{})
- func Errorf(reqId string, format string, v ...interface{})
- func Fatal(reqId string, v ...interface{})
- func Fatalf(reqId string, format string, v ...interface{})
- func Fatalln(reqId string, v ...interface{})
- func GenReqId() string
- func Info(reqId string, v ...interface{})
- func Infof(reqId string, format string, v ...interface{})
- func NewContext(ctx Context, xl *Logger) Context
- func NewContextWith(ctx Context, a interface{}) Context
- func NewContextWithRW(ctx Context, w http.ResponseWriter, r *http.Request) Context
- func NewContextWithReq(ctx Context, req *http.Request) Context
- func Panic(reqId string, v ...interface{})
- func Panicf(reqId string, format string, v ...interface{})
- func Panicln(reqId string, v ...interface{})
- func SetFlags(flag int)
- func SetGenReqId(f func() string)
- func SetOutput(w io.Writer)
- func SetOutputLevel(lvl int)
- func SingleStack(reqId string, v ...interface{})
- func Stack(reqId string, v ...interface{})
- func Warn(reqId string, v ...interface{})
- func Warnf(reqId string, format string, v ...interface{})
- type Logger
- func FromContext(ctx Context) (xl *Logger, ok bool)
- func FromContextSafe(ctx Context) (xl *Logger)
- func New(w http.ResponseWriter, req *http.Request) *Logger
- func NewDummy() *Logger
- func NewDummyWithCtx(ctx context.Context) *Logger
- func NewWith(a interface{}) *Logger
- func NewWithReq(req *http.Request) *Logger
- func (xlog *Logger) Context() context.Context
- func (xlog *Logger) CtxWithValue(key, value interface{}) context.Context
- func (xlog *Logger) Debug(v ...interface{})
- func (xlog *Logger) Debugf(format string, v ...interface{})
- func (xlog *Logger) Error(v ...interface{})
- func (xlog *Logger) Errorf(format string, v ...interface{})
- func (xlog *Logger) Fatal(v ...interface{})
- func (xlog *Logger) Fatalf(format string, v ...interface{})
- func (xlog *Logger) Fatalln(v ...interface{})
- func (xlog *Logger) Header() http.Header
- func (xlog *Logger) Info(v ...interface{})
- func (xlog *Logger) Infof(format string, v ...interface{})
- func (xlog *Logger) Panic(v ...interface{})
- func (xlog *Logger) Panicf(format string, v ...interface{})
- func (xlog *Logger) Panicln(v ...interface{})
- func (xlog *Logger) Print(v ...interface{})
- func (xlog *Logger) Printf(format string, v ...interface{})
- func (xlog *Logger) Println(v ...interface{})
- func (xlog *Logger) ReqId() string
- func (xlog *Logger) SingleStack(v ...interface{})
- func (xlog *Logger) Spawn() *Logger
- func (xlog *Logger) SpawnWithCtx() *Logger
- func (xlog *Logger) Stack(v ...interface{})
- func (xlog *Logger) Warn(v ...interface{})
- func (xlog *Logger) Warnf(format string, v ...interface{})
- func (xlog *Logger) WithContext(ctx context.Context) *Logger
- func (xlog *Logger) Xbill(key string, value interface{})
- func (xlog *Logger) Xget() []string
- func (xlog *Logger) XgetTag() []string
- func (xlog *Logger) Xlog(v ...interface{})
- func (xlog *Logger) Xlogf(format string, v ...interface{})
- func (xlog *Logger) Xprof(modFn string, start time.Time, err error)
- func (xlog *Logger) Xprof2(modFn string, dur time.Duration, err error)
- func (xlog *Logger) Xput(logs []string)
- func (xlog *Logger) XputTag(tags []string)
- func (xlog *Logger) Xtag(v ...interface{})
- func (xlog *Logger) Xtrack(modFn string, start time.Time, errTrack *error)
- func (xlog *Logger) Xuid(uid uint32)
Constants ¶
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 )
const ( Ldebug = log.Ldebug Linfo = log.Linfo Lwarn = log.Lwarn Lerror = log.Lerror Lpanic = log.Lpanic Lfatal = log.Lfatal )
Variables ¶
var ForceSpawnCtx bool
var UseReqCtx bool
Functions ¶
func Fatal ¶
func Fatal(reqId string, v ...interface{})
Fatal is equivalent to Print() 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 NewContext ¶
func NewContext(ctx Context, xl *Logger) Context
func NewContextWith ¶
func NewContextWith(ctx Context, a interface{}) Context
Born a context with:
- provided req id (if @a is reqIder)
- provided header (if @a is header)
- **DUMMY** trace recorder (if @a cannot record)
func NewContextWithRW ¶
func NewContextWithRW(ctx Context, w http.ResponseWriter, r *http.Request) Context
func NewContextWithReq ¶
func Panic ¶
func Panic(reqId string, v ...interface{})
Panic is equivalent to Print() 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 SetGenReqId ¶
func SetGenReqId(f func() string)
func SetOutputLevel ¶
func SetOutputLevel(lvl int)
func SingleStack ¶
func SingleStack(reqId string, v ...interface{})
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func FromContext ¶
func FromContextSafe ¶
func FromContextSafe(ctx Context) (xl *Logger)
func NewDummy ¶
func NewDummy() *Logger
Born a logger with:
- new random req id
- **DUMMY** trace recorder (will not record anything)
func NewDummyWithCtx ¶
Born a logger with:
- new random req id
- provided ctx
- **DUMMY** trace recorder (will not record anything)
func NewWith ¶
func NewWith(a interface{}) *Logger
Born a logger with:
- provided req id (if @a is reqIder)
- provided header (if @a is header)
- provided context (if @a is contexter)
- **DUMMY** trace recorder (if @a cannot record)
func NewWithReq ¶
func (*Logger) CtxWithValue ¶
func (*Logger) Fatal ¶
func (xlog *Logger) Fatal(v ...interface{})
Fatal is equivalent to Print() 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) Panic ¶
func (xlog *Logger) Panic(v ...interface{})
Panic is equivalent to Print() 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 ¶
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) SingleStack ¶
func (xlog *Logger) SingleStack(v ...interface{})
func (*Logger) Spawn ¶
Spawn a child logger with:
- same req id with parent
- same trace recorder with parent(history compatibility consideration)
- a backgroud ctx, so when the xlog.ctx is done, the new xlog can continue 如果需要继承xlog 的生命周期,请使用 SpawnWithCtx
func (*Logger) SpawnWithCtx ¶
Spawn a child logger with:
- same req id with parent
- same trace recorder with parent(history compatibility consideration)
- same ctx with parent Warning: 调用这个方法,新的 routine 将会继承上游请求的生命周期——上游请求关闭,该 routine 也会关闭。 因此,一定要保证新的 routine 在主 routine 之前结束(可以考虑使用 waitgroup 来实现)。 此外,即使两个 routine 看似"同时"关闭,比如使用 multiwriter,也可能会产生问题,因为multiwriter 实际上还是有先后。
func (*Logger) WithContext ¶
============================================================================ Warning: 仅限在少数特殊场合使用,返回的Logger和原来的Logger并不能并发调用! 返回一个只替换原先Logger的ctx的Logger
func (*Logger) Xprof ¶
* 用法示意:
func Foo(log xlog.*Logger) { ... now := time.Now() err := longtimeOperation() log.Xprof("longtimeOperation", now, err) ... }