mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-14 14:56:27 +03:00
caddyhttp: Add --debug flag to commands
file-server and reverse-proxy This might be useful!
This commit is contained in:
parent
48d723c07c
commit
b6cec37893
4 changed files with 25 additions and 3 deletions
|
@ -223,7 +223,7 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
|
||||||
hasDefaultLog = true
|
hasDefaultLog = true
|
||||||
}
|
}
|
||||||
if _, ok := options["debug"]; ok && ncl.log.Level == "" {
|
if _, ok := options["debug"]; ok && ncl.log.Level == "" {
|
||||||
ncl.log.Level = "DEBUG"
|
ncl.log.Level = zap.DebugLevel.CapitalString()
|
||||||
}
|
}
|
||||||
customLogs = append(customLogs, ncl)
|
customLogs = append(customLogs, ncl)
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
|
||||||
if _, ok := options["debug"]; ok {
|
if _, ok := options["debug"]; ok {
|
||||||
customLogs = append(customLogs, namedCustomLog{
|
customLogs = append(customLogs, namedCustomLog{
|
||||||
name: "default",
|
name: "default",
|
||||||
log: &caddy.CustomLog{Level: "DEBUG"},
|
log: &caddy.CustomLog{Level: zap.DebugLevel.CapitalString()},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||||
caddytpl "github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
|
caddytpl "github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
|
||||||
"github.com/caddyserver/certmagic"
|
"github.com/caddyserver/certmagic"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -70,6 +71,7 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
|
||||||
browse := fs.Bool("browse")
|
browse := fs.Bool("browse")
|
||||||
templates := fs.Bool("templates")
|
templates := fs.Bool("templates")
|
||||||
accessLog := fs.Bool("access-log")
|
accessLog := fs.Bool("access-log")
|
||||||
|
debug := fs.Bool("debug")
|
||||||
|
|
||||||
var handlers []json.RawMessage
|
var handlers []json.RawMessage
|
||||||
|
|
||||||
|
@ -130,6 +132,14 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
cfg.Logging = &caddy.Logging{
|
||||||
|
Logs: map[string]*caddy.CustomLog{
|
||||||
|
"default": {Level: zap.DebugLevel.CapitalString()},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err := caddy.Run(cfg)
|
err := caddy.Run(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return caddy.ExitCodeFailedStartup, err
|
return caddy.ExitCodeFailedStartup, err
|
||||||
|
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp/headers"
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp/headers"
|
||||||
"github.com/caddyserver/caddy/v2/modules/caddytls"
|
"github.com/caddyserver/caddy/v2/modules/caddytls"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -62,6 +63,7 @@ default, all incoming headers are passed through unmodified.)
|
||||||
fs.Bool("change-host-header", false, "Set upstream Host header to address of upstream")
|
fs.Bool("change-host-header", false, "Set upstream Host header to address of upstream")
|
||||||
fs.Bool("insecure", false, "Disable TLS verification (WARNING: DISABLES SECURITY BY NOT VERIFYING SSL CERTIFICATES!)")
|
fs.Bool("insecure", false, "Disable TLS verification (WARNING: DISABLES SECURITY BY NOT VERIFYING SSL CERTIFICATES!)")
|
||||||
fs.Bool("internal-certs", false, "Use internal CA for issuing certs")
|
fs.Bool("internal-certs", false, "Use internal CA for issuing certs")
|
||||||
|
fs.Bool("debug", false, "Enable verbose debug logs")
|
||||||
return fs
|
return fs
|
||||||
}(),
|
}(),
|
||||||
})
|
})
|
||||||
|
@ -74,6 +76,7 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
|
||||||
changeHost := fs.Bool("change-host-header")
|
changeHost := fs.Bool("change-host-header")
|
||||||
insecure := fs.Bool("insecure")
|
insecure := fs.Bool("insecure")
|
||||||
internalCerts := fs.Bool("internal-certs")
|
internalCerts := fs.Bool("internal-certs")
|
||||||
|
debug := fs.Bool("debug")
|
||||||
|
|
||||||
httpPort := strconv.Itoa(caddyhttp.DefaultHTTPPort)
|
httpPort := strconv.Itoa(caddyhttp.DefaultHTTPPort)
|
||||||
httpsPort := strconv.Itoa(caddyhttp.DefaultHTTPSPort)
|
httpsPort := strconv.Itoa(caddyhttp.DefaultHTTPSPort)
|
||||||
|
@ -198,6 +201,14 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
|
||||||
AppsRaw: appsRaw,
|
AppsRaw: appsRaw,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
cfg.Logging = &caddy.Logging{
|
||||||
|
Logs: map[string]*caddy.CustomLog{
|
||||||
|
"default": {Level: zap.DebugLevel.CapitalString()},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = caddy.Run(cfg)
|
err = caddy.Run(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return caddy.ExitCodeFailedStartup, err
|
return caddy.ExitCodeFailedStartup, err
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||||
caddycmd "github.com/caddyserver/caddy/v2/cmd"
|
caddycmd "github.com/caddyserver/caddy/v2/cmd"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -403,7 +404,7 @@ func cmdRespond(fl caddycmd.Flags) (int, error) {
|
||||||
if debug {
|
if debug {
|
||||||
cfg.Logging = &caddy.Logging{
|
cfg.Logging = &caddy.Logging{
|
||||||
Logs: map[string]*caddy.CustomLog{
|
Logs: map[string]*caddy.CustomLog{
|
||||||
"default": {Level: "DEBUG"},
|
"default": {Level: zap.DebugLevel.CapitalString()},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue