本文整理匯總了Golang中github.com/juju/loggo.Logger.IsTraceEnabled方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.IsTraceEnabled方法的具體用法?Golang Logger.IsTraceEnabled怎麽用?Golang Logger.IsTraceEnabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/loggo.Logger
的用法示例。
在下文中一共展示了Logger.IsTraceEnabled方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRootLogger
func (*loggerSuite) TestRootLogger(c *gc.C) {
root := loggo.Logger{}
c.Assert(root.Name(), gc.Equals, "<root>")
c.Assert(root.IsErrorEnabled(), gc.Equals, true)
c.Assert(root.IsWarningEnabled(), gc.Equals, true)
c.Assert(root.IsInfoEnabled(), gc.Equals, false)
c.Assert(root.IsDebugEnabled(), gc.Equals, false)
c.Assert(root.IsTraceEnabled(), gc.Equals, false)
}
示例2: TestRootLogger
func (s *LoggerSuite) TestRootLogger(c *gc.C) {
root := loggo.Logger{}
c.Check(root.Name(), gc.Equals, "<root>")
c.Check(root.LogLevel(), gc.Equals, loggo.WARNING)
c.Check(root.IsErrorEnabled(), gc.Equals, true)
c.Check(root.IsWarningEnabled(), gc.Equals, true)
c.Check(root.IsInfoEnabled(), gc.Equals, false)
c.Check(root.IsDebugEnabled(), gc.Equals, false)
c.Check(root.IsTraceEnabled(), gc.Equals, false)
}
示例3: RespondDecorator
// RespondDecorator returns an autorest.RespondDecorator that
// logs responses at trace level.
func RespondDecorator(logger loggo.Logger) autorest.RespondDecorator {
return func(r autorest.Responder) autorest.Responder {
return autorest.ResponderFunc(func(resp *http.Response) error {
if logger.IsTraceEnabled() {
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
logger.Tracef("failed to dump response: %v", err)
logger.Tracef("%+v", resp)
} else {
logger.Tracef("%s", dump)
}
}
return r.Respond(resp)
})
}
}
示例4: PrepareDecorator
// PrepareDecorator returns an autorest.PrepareDecorator that
// logs requests at trace level.
func PrepareDecorator(logger loggo.Logger) autorest.PrepareDecorator {
return func(p autorest.Preparer) autorest.Preparer {
return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
if logger.IsTraceEnabled() {
dump, err := httputil.DumpRequest(r, true)
if err != nil {
logger.Tracef("failed to dump request: %v", err)
logger.Tracef("%+v", r)
} else {
logger.Tracef("%s", dump)
}
}
return p.Prepare(r)
})
}
}
示例5: sendRequest
// Sends the specified request to URL and checks that the HTTP response status is as expected.
// reqReader: a reader returning the data to send.
// length: the number of bytes to send.
// headers: HTTP headers to include with the request.
// expectedStatus: a slice of allowed response status codes.
func (c *Client) sendRequest(method, URL string, reqReader io.Reader, length int, headers http.Header,
expectedStatus []int, logger *loggo.Logger) (rc io.ReadCloser, respHeader *http.Header, err error) {
reqData := make([]byte, length)
if reqReader != nil {
nrRead, err := io.ReadFull(reqReader, reqData)
if err != nil {
err = errors.Newf(err, "failed reading the request data, read %v of %v bytes", nrRead, length)
return rc, respHeader, err
}
}
rawResp, err := c.sendRateLimitedRequest(method, URL, headers, reqData, logger)
if err != nil {
return
}
if logger != nil && logger.IsTraceEnabled() {
logger.Tracef("Request: %s %s\n", method, URL)
logger.Tracef("Request header: %s\n", headers)
logger.Tracef("Request body: %s\n", reqData)
logger.Tracef("Response: %s\n", rawResp.Status)
logger.Tracef("Response header: %s\n", rawResp.Header)
logger.Tracef("Response body: %s\n", rawResp.Body)
logger.Tracef("Response error: %s\n", err)
}
foundStatus := false
if len(expectedStatus) == 0 {
expectedStatus = []int{http.StatusOK}
}
for _, status := range expectedStatus {
if rawResp.StatusCode == status {
foundStatus = true
break
}
}
if !foundStatus && len(expectedStatus) > 0 {
err = handleError(URL, rawResp)
rawResp.Body.Close()
return
}
return rawResp.Body, &rawResp.Header, err
}