Documentation ¶
Overview ¶
Package trace A log wrapper based on google glog. Mainly used for a http request process.
Index ¶
- Constants
- func GetRealIPFromContext(ctx context.Context) string
- func GetUserInfoFromContext(ctx context.Context) (string, error)
- func HandleCrash(fn ...func(r interface{}))
- func HandlerFunc(name string, handler gin.HandlerFunc) gin.HandlerFunc
- func LogCrashStack(ctx context.Context, r interface{})
- func Stacks(all bool) []byte
- func WithTraceForContext(ctx context.Context, traceName string, traceID ...string) context.Context
- func WithTraceForContext2(ctx context.Context, tracer Trace) context.Context
- func WithTraceForGinContext(ctx context.Context, traceName string, traceID ...string) *gin.Context
- type Trace
Constants ¶
const (
DefaultLoginUser = "203832"
)
Variables ¶
This section is empty.
Functions ¶
func GetRealIPFromContext ¶
GetRealIPFromContext get the remote endpoint from request, if not found, return an empty string
func HandlerFunc ¶
func HandlerFunc(name string, handler gin.HandlerFunc) gin.HandlerFunc
HandleFunc wrap a trace handle func outer the original http handle func
func WithTraceForContext ¶
WithTraceForContext will return a new context wrapped a trace handler around the original ctx
func WithTraceForContext2 ¶
WithTraceForContext2 will return a new context wrapped a trace handler around the original ctx
Types ¶
type Trace ¶
type Trace interface { // Parent will return the parent trace Parent() Trace // Name will return the current trace name Name() string // SetName will set a new name for the Trace object SetName(name string) // ID will return the current trace id ID() string // Start will return the current trace start time Start() time.Time // Duration will return the current trace Duration Duration() time.Duration // Stack will return current stack Stack(all ...bool) string // String will return a string-serialized trace String() string SetLogger(l *dlog.Logger) Trace // contains filtered or unexported methods }
Trace is a log trace utils wrapped on glog, can be used to trace a http request and its subrequests
func GetTraceFromContext ¶
GetTraceFromContext get the Trace var from the context, if there is no such a trace utility, return nil
func GetTraceFromRequest ¶
GetTraceFromRequest get the Trace var from the req context, if there is no such a trace utility, return nil
func WithParent ¶
WithParent will create a Trace use a parent Trace and a identified name