mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-22 07:30:25 +00:00
capture http servers error logs
otherwise they will be printed to stdout
This commit is contained in:
parent
4b522a2455
commit
6d84c5b9e3
4 changed files with 24 additions and 0 deletions
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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{
|
||||||
|
|
Loading…
Reference in a new issue