github.com/rohankumardubey/nomad@v0.11.8/command/agent/http_stdlog.go (about) 1 package agent 2 3 import ( 4 "bytes" 5 "log" 6 7 hclog "github.com/hashicorp/go-hclog" 8 ) 9 10 func newHTTPServerLogger(logger hclog.Logger) *log.Logger { 11 return log.New(&httpServerLoggerAdapter{logger}, "", 0) 12 } 13 14 // a logger adapter that forwards http server logs as a Trace level 15 // hclog log entries. Logs related to panics are forwarded with Error level. 16 // 17 // HTTP server logs are typically spurious as they represent HTTP 18 // client errors (e.g. TLS handshake failures). 19 type httpServerLoggerAdapter struct { 20 logger hclog.Logger 21 } 22 23 func (l *httpServerLoggerAdapter) Write(data []byte) (int, error) { 24 if bytes.Contains(data, []byte("panic")) { 25 str := string(bytes.TrimRight(data, " \t\n")) 26 l.logger.Error(str) 27 } else if l.logger.IsTrace() { 28 str := string(bytes.TrimRight(data, " \t\n")) 29 l.logger.Trace(str) 30 } 31 32 return len(data), nil 33 }