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, 03:00 UTC
cmd: Reduce spammy logs from --watch
Matthew Holt committed
May 12, 2023 at 11:04 UTC
5ebb7d496da765fd0263161cd306ecf86b609485
1 file changed
+16
-7
cmd/main.go
+16
-7
@@ -89,6 +89,10 @@ func handlePingbackConn(conn net.Conn, expect []byte) error {
89
// and returns the resulting JSON config bytes along with
90
// the name of the loaded config file (if any).
91
func LoadConfig(configFile, adapterName string) ([]byte, string, error) {
92
+ return loadConfigWithLogger(caddy.Log(), configFile, adapterName)
93
+}
94
+
95
+func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([]byte, string, error) {
96
// specifying an adapter without a config file is ambiguous
97
if adapterName != "" && configFile == "" {
98
return nil, "", fmt.Errorf("cannot adapt config without config file (use --config)")
@@ -107,9 +111,11 @@ func LoadConfig(configFile, adapterName string) ([]byte, string, error) {
111
if err != nil {
112
return nil, "", fmt.Errorf("reading config file: %v", err)
113
}
110
- caddy.Log().Info("using provided configuration",
111
- zap.String("config_file", configFile),
112
- zap.String("config_adapter", adapterName))
114
+ if logger != nil {
115
+ logger.Info("using provided configuration",
116
+ zap.String("config_file", configFile),
117
+ zap.String("config_adapter", adapterName))
118
+ }
119
} else if adapterName == "" {
120
// as a special case when no config file or adapter
121
// is specified, see if the Caddyfile adapter is
@@ -126,7 +132,9 @@ func LoadConfig(configFile, adapterName string) ([]byte, string, error) {
132
} else {
133
// success reading default Caddyfile
134
configFile = "Caddyfile"
129
- caddy.Log().Info("using adjacent Caddyfile")
135
+ if logger != nil {
136
+ logger.Info("using adjacent Caddyfile")
137
+ }
138
}
139
}
140
}
@@ -161,7 +169,9 @@ func LoadConfig(configFile, adapterName string) ([]byte, string, error) {
169
if warn.Directive != "" {
170
msg = fmt.Sprintf("%s: %s", warn.Directive, warn.Message)
171
}
164
- caddy.Log().Warn(msg, zap.String("adapter", adapterName), zap.String("file", warn.File), zap.Int("line", warn.Line))
172
+ if logger != nil {
173
+ logger.Warn(msg, zap.String("adapter", adapterName), zap.String("file", warn.File), zap.Int("line", warn.Line))
174
+ }
175
}
176
config = adaptedConfig
177
}
@@ -192,7 +202,7 @@ func watchConfigFile(filename, adapterName string) {
202
}
203
204
// get current config
195
- lastCfg, _, err := LoadConfig(filename, adapterName)
205
+ lastCfg, _, err := loadConfigWithLogger(nil, filename, adapterName)
206
if err != nil {
207
logger().Error("unable to load latest config", zap.Error(err))
208
return
@@ -203,7 +213,6 @@ func watchConfigFile(filename, adapterName string) {
213
// begin poller
214
//nolint:staticcheck
215
for range time.Tick(1 * time.Second) {
206
-
216
// get current config
217
newCfg, _, err := LoadConfig(filename, adapterName)
218
if err != nil {