@marcel91200 / caddy Mirror · read-only / commits / b6cec378
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 11:45 UTC

caddyhttp: Add --debug flag to commands

file-server and reverse-proxy This might be useful!

Matthew Holt committed Sep 15, 2022 at 23:10 UTC b6cec3789342c2408d878359d4ed07e3789611ac
4 files changed +25 -3
caddyconfig/httpcaddyfile/httptype.go
+2 -2
@@ -223,7 +223,7 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
223 hasDefaultLog = true
224 }
225 if _, ok := options["debug"]; ok && ncl.log.Level == "" {
226 - ncl.log.Level = "DEBUG"
226 + ncl.log.Level = zap.DebugLevel.CapitalString()
227 }
228 customLogs = append(customLogs, ncl)
229 }
@@ -241,7 +241,7 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
241 if _, ok := options["debug"]; ok {
242 customLogs = append(customLogs, namedCustomLog{
243 name: "default",
244 - log: &caddy.CustomLog{Level: "DEBUG"},
244 + log: &caddy.CustomLog{Level: zap.DebugLevel.CapitalString()},
245 })
246 }
247 }
modules/caddyhttp/fileserver/command.go
+10
@@ -27,6 +27,7 @@ import (
27 "github.com/caddyserver/caddy/v2/modules/caddyhttp"
28 caddytpl "github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
29 "github.com/caddyserver/certmagic"
30 + "go.uber.org/zap"
31 )
32
33 func init() {
@@ -70,6 +71,7 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
71 browse := fs.Bool("browse")
72 templates := fs.Bool("templates")
73 accessLog := fs.Bool("access-log")
74 + debug := fs.Bool("debug")
75
76 var handlers []json.RawMessage
77
@@ -130,6 +132,14 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
132 },
133 }
134
135 + if debug {
136 + cfg.Logging = &caddy.Logging{
137 + Logs: map[string]*caddy.CustomLog{
138 + "default": {Level: zap.DebugLevel.CapitalString()},
139 + },
140 + }
141 + }
142 +
143 err := caddy.Run(cfg)
144 if err != nil {
145 return caddy.ExitCodeFailedStartup, err
modules/caddyhttp/reverseproxy/command.go
+11
@@ -28,6 +28,7 @@ import (
28 "github.com/caddyserver/caddy/v2/modules/caddyhttp"
29 "github.com/caddyserver/caddy/v2/modules/caddyhttp/headers"
30 "github.com/caddyserver/caddy/v2/modules/caddytls"
31 + "go.uber.org/zap"
32 )
33
34 func init() {
@@ -62,6 +63,7 @@ default, all incoming headers are passed through unmodified.)
63 fs.Bool("change-host-header", false, "Set upstream Host header to address of upstream")
64 fs.Bool("insecure", false, "Disable TLS verification (WARNING: DISABLES SECURITY BY NOT VERIFYING SSL CERTIFICATES!)")
65 fs.Bool("internal-certs", false, "Use internal CA for issuing certs")
66 + fs.Bool("debug", false, "Enable verbose debug logs")
67 return fs
68 }(),
69 })
@@ -74,6 +76,7 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
76 changeHost := fs.Bool("change-host-header")
77 insecure := fs.Bool("insecure")
78 internalCerts := fs.Bool("internal-certs")
79 + debug := fs.Bool("debug")
80
81 httpPort := strconv.Itoa(caddyhttp.DefaultHTTPPort)
82 httpsPort := strconv.Itoa(caddyhttp.DefaultHTTPSPort)
@@ -198,6 +201,14 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
201 AppsRaw: appsRaw,
202 }
203
204 + if debug {
205 + cfg.Logging = &caddy.Logging{
206 + Logs: map[string]*caddy.CustomLog{
207 + "default": {Level: zap.DebugLevel.CapitalString()},
208 + },
209 + }
210 + }
211 +
212 err = caddy.Run(cfg)
213 if err != nil {
214 return caddy.ExitCodeFailedStartup, err
modules/caddyhttp/staticresp.go
+2 -1
@@ -31,6 +31,7 @@ import (
31 "github.com/caddyserver/caddy/v2/caddyconfig"
32 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
33 caddycmd "github.com/caddyserver/caddy/v2/cmd"
34 + "go.uber.org/zap"
35 )
36
37 func init() {
@@ -403,7 +404,7 @@ func cmdRespond(fl caddycmd.Flags) (int, error) {
404 if debug {
405 cfg.Logging = &caddy.Logging{
406 Logs: map[string]*caddy.CustomLog{
406 - "default": {Level: "DEBUG"},
407 + "default": {Level: zap.DebugLevel.CapitalString()},
408 },
409 }
410 }