本文整理匯總了Golang中github.com/cortesi/termlog.TermLog.Group方法的典型用法代碼示例。如果您正苦於以下問題:Golang TermLog.Group方法的具體用法?Golang TermLog.Group怎麽用?Golang TermLog.Group使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cortesi/termlog.TermLog
的用法示例。
在下文中一共展示了TermLog.Group方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WrapHandler
// WrapHandler wraps an httpctx.Handler in the paraphernalia needed by devd for
// logging, latency, and so forth.
func (dd *Devd) WrapHandler(log termlog.TermLog, next httpctx.Handler) http.Handler {
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
revertOriginalHost(r)
timr := timer.Timer{}
sublog := log.Group()
defer func() {
timing := termlog.DefaultPalette.Timestamp.SprintFunc()("timing: ")
sublog.SayAs("timer", timing+timr.String())
sublog.Done()
}()
if matchStringAny(dd.IgnoreLogs, fmt.Sprintf("%s%s", r.URL.Host, r.RequestURI)) {
sublog.Quiet()
}
timr.RequestHeaders()
time.Sleep(time.Millisecond * time.Duration(dd.Latency))
dpath := r.URL.String()
if !strings.HasPrefix(dpath, "/") {
dpath = "/" + dpath
}
sublog.Say("%s %s", r.Method, dpath)
LogHeader(sublog, r.Header)
ctx := timr.NewContext(context.Background())
ctx = termlog.NewContext(ctx, sublog)
if dd.AddHeaders != nil {
for h, vals := range *dd.AddHeaders {
if strings.ToLower(h) == "host" {
if len(vals) > 0 {
r.Host = vals[0]
}
} else {
for _, v := range vals {
w.Header().Set(h, v)
}
}
}
}
next.ServeHTTPContext(
ctx,
&ResponseLogWriter{Log: sublog, Resp: w, Timer: &timr},
r,
)
})
return h
}