capture http servers error logs

otherwise they will be printed to stdout
This commit is contained in:
Nicola Murino 2021-01-03 10:38:28 +01:00
parent 4b522a2455
commit 6d84c5b9e3
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
4 changed files with 24 additions and 0 deletions

View file

@ -9,6 +9,7 @@ package httpd
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"log"
"net/http" "net/http"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -154,6 +155,7 @@ func (c Conf) Initialize(configDir string) error {
WriteTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second,
IdleTimeout: 120 * time.Second, IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 16, // 64KB MaxHeaderBytes: 1 << 16, // 64KB
ErrorLog: log.New(&logger.StdLoggerWrapper{Sender: logSender}, "", 0),
} }
if certificateFile != "" && certificateKeyFile != "" { if certificateFile != "" && certificateKeyFile != "" {
certMgr, err = common.NewCertManager(certificateFile, certificateKeyFile, logSender) certMgr, err = common.NewCertManager(certificateFile, certificateKeyFile, logSender)

View file

@ -40,6 +40,24 @@ var (
rollingLogger *lumberjack.Logger rollingLogger *lumberjack.Logger
) )
// StdLoggerWrapper is a wrapper for standard logger compatibility
type StdLoggerWrapper struct {
Sender string
}
// Write implements the io.Writer interface. This is useful to set as a writer
// for the standard library log.
func (l *StdLoggerWrapper) Write(p []byte) (n int, err error) {
n = len(p)
if n > 0 && p[n-1] == '\n' {
// Trim CR added by stdlog.
p = p[0 : n-1]
}
Log(LevelError, l.Sender, "", string(p))
return
}
// GetLogger get the configured logger instance // GetLogger get the configured logger instance
func GetLogger() *zerolog.Logger { func GetLogger() *zerolog.Logger {
return &logger return &logger

View file

@ -6,6 +6,7 @@ package telemetry
import ( import (
"crypto/tls" "crypto/tls"
"log"
"net/http" "net/http"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -82,6 +83,7 @@ func (c Conf) Initialize(configDir string) error {
WriteTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second,
IdleTimeout: 120 * time.Second, IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 14, // 16KB MaxHeaderBytes: 1 << 14, // 16KB
ErrorLog: log.New(&logger.StdLoggerWrapper{Sender: logSender}, "", 0),
} }
if certificateFile != "" && certificateKeyFile != "" { if certificateFile != "" && certificateKeyFile != "" {
certMgr, err = common.NewCertManager(certificateFile, certificateKeyFile, logSender) certMgr, err = common.NewCertManager(certificateFile, certificateKeyFile, logSender)

View file

@ -5,6 +5,7 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"log"
"net/http" "net/http"
"path" "path"
"path/filepath" "path/filepath"
@ -42,6 +43,7 @@ func (s *webDavServer) listenAndServe() error {
ReadHeaderTimeout: 30 * time.Second, ReadHeaderTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second, IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 16, // 64KB MaxHeaderBytes: 1 << 16, // 64KB
ErrorLog: log.New(&logger.StdLoggerWrapper{Sender: logSender}, "", 0),
} }
if s.config.Cors.Enabled { if s.config.Cors.Enabled {
c := cors.New(cors.Options{ c := cors.New(cors.Options{