Documentation ¶
Index ¶
- func GetRealIPFromContext(ctx context.Context) string
- func HandleCrash(fn ...func(r interface{}))
- func HandleFunc(name string, handler func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request)
- func Handler(name string, handler http.Handler) http.Handler
- 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
- type Trace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRealIPFromContext ¶
GetRealIPFromContext get the remote endpoint from request, if not found, return an empty string
func HandleFunc ¶
func HandleFunc(name string, handler func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request)
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
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 // Info will print the args as the info level log Info(args ...interface{}) // Infof will print the args with a format as the info level log Infof(format string, args ...interface{}) // Warn will print the args as the warn level log Warn(args ...interface{}) // Warnf will print the args with a format as the warn level log Warnf(format string, args ...interface{}) // Error will print the args as the error level log Error(args ...interface{}) // Errorf will print the args with a format as the error level log Errorf(format string, args ...interface{}) // Stack will return current stack Stack(all ...bool) string // String will return a string-serialized trace String() string // Fatalf will print log and exit process Fatalf(format string, args ...interface{}) // Fatalf will print log and exit process Fatal(args ...interface{}) Debug(args ...interface{}) Debugf(format string, args ...interface{}) // 1. 支持命令行参数指定Level, eg: -v=3 // 2. 支持环境变量支持Level, export LOGVERB=3 V(level int) Trace Enable() bool }
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
Click to show internal directories.
Click to hide internal directories.