mirror of
https://github.com/umputun/reproxy.git
synced 2025-11-23 22:04:57 +02:00
allow optional stdout logging
This commit is contained in:
@@ -45,6 +45,7 @@ var opts struct {
|
||||
} `group:"assets" namespace:"assets" env-namespace:"ASSETS"`
|
||||
|
||||
Logger struct {
|
||||
StdOut bool `long:"stdout" env:"STDOUT" description:"enable stdout logging"`
|
||||
Enabled bool `long:"enabled" env:"ENABLED" description:"enable access and error rotated logs"`
|
||||
FileName string `long:"file" env:"FILE" default:"access.log" description:"location of access log"`
|
||||
MaxSize int `long:"max-size" env:"MAX_SIZE" default:"100" description:"maximum size in megabytes before it gets rotated"`
|
||||
@@ -148,6 +149,7 @@ func main() {
|
||||
SSLConfig: sslConfig,
|
||||
ProxyHeaders: opts.ProxyHeaders,
|
||||
AccessLog: accessLog,
|
||||
StdOutEnabled: opts.Logger.StdOut,
|
||||
DisableSignature: opts.NoSignature,
|
||||
Timeouts: proxy.Timeouts{
|
||||
ReadHeader: opts.Timeouts.ReadHeader,
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
log "github.com/go-pkgz/lgr"
|
||||
R "github.com/go-pkgz/rest"
|
||||
"github.com/go-pkgz/rest/logger"
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -21,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
// Http is a proxy server for both http and https
|
||||
type Http struct { //nolint golint
|
||||
type Http struct { // nolint golint
|
||||
Matcher
|
||||
Address string
|
||||
AssetsLocation string
|
||||
@@ -32,6 +33,7 @@ type Http struct { //nolint golint
|
||||
SSLConfig SSLConfig
|
||||
Version string
|
||||
AccessLog io.Writer
|
||||
StdOutEnabled bool
|
||||
DisableSignature bool
|
||||
Timeouts Timeouts
|
||||
}
|
||||
@@ -88,6 +90,7 @@ func (h *Http) Run(ctx context.Context) error {
|
||||
h.pingHandler,
|
||||
h.healthMiddleware,
|
||||
h.accessLogHandler(h.AccessLog),
|
||||
h.stdoutLogHandler(h.StdOutEnabled),
|
||||
R.SizeLimit(h.MaxBodySize),
|
||||
R.Headers(h.ProxyHeaders...),
|
||||
h.gzipHandler(),
|
||||
@@ -240,6 +243,19 @@ func (h *Http) accessLogHandler(wr io.Writer) func(next http.Handler) http.Handl
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Http) stdoutLogHandler(enable bool) func(next http.Handler) http.Handler {
|
||||
|
||||
if enable {
|
||||
return logger.New(logger.Log(log.Default()), logger.Prefix("[INFO]")).Handler
|
||||
}
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Http) makeHTTPServer(addr string, router http.Handler) *http.Server {
|
||||
return &http.Server{
|
||||
Addr: addr,
|
||||
|
||||
Reference in New Issue
Block a user