Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
cmd: file-server: add --access-log flag (#3454)
Rui Lopes committed
May 26, 2020 at 22:04 UTC
aa20878887c592fd79bef2a9943b1013ead8bac2
1 file changed
+6
-1
modules/caddyhttp/fileserver/command.go
+6
-1
@@ -33,7 +33,7 @@ func init() {
33
caddycmd.RegisterCommand(caddycmd.Command{
34
Name: "file-server",
35
Func: cmdFileServer,
36
- Usage: "[--domain <example.com>] [--root <path>] [--listen <addr>] [--browse]",
36
+ Usage: "[--domain <example.com>] [--root <path>] [--listen <addr>] [--browse] [--access-log]",
37
Short: "Spins up a production-ready file server",
38
Long: `
39
A simple but production-ready file server. Useful for quick deployments,
@@ -55,6 +55,7 @@ respond with a file listing.`,
55
fs.String("listen", "", "The address to which to bind the listener")
56
fs.Bool("browse", false, "Enable directory browsing")
57
fs.Bool("templates", false, "Enable template rendering")
58
+ fs.Bool("access-log", false, "Enable the access log")
59
return fs
60
}(),
61
})
@@ -68,6 +69,7 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
69
listen := fs.String("listen")
70
browse := fs.Bool("browse")
71
templates := fs.Bool("templates")
72
+ accessLog := fs.Bool("access-log")
73
74
var handlers []json.RawMessage
75
@@ -107,6 +109,9 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
109
}
110
}
111
server.Listen = []string{listen}
112
+ if accessLog {
113
+ server.Logs = &caddyhttp.ServerLogConfig{}
114
+ }
115
116
httpApp := caddyhttp.App{
117
Servers: map[string]*caddyhttp.Server{"static": server},