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, 01:30 UTC
logging: Remove common_log field and single_field encoder (#4149) (#4282)
Matt Holt committed
Nov 28, 2021 at 23:08 UTC
0eb0b60f47bddcf24f6af9265e60044033555ff2
4 files changed
+1
-100
caddyconfig/httpcaddyfile/builtins_test.go
+1
-2
@@ -37,7 +37,6 @@ func TestLogDirectiveSyntax(t *testing.T) {
37
format filter {
38
wrap console
39
fields {
40
- common_log delete
40
request>remote_addr ip_mask {
41
ipv4 24
42
ipv6 32
@@ -47,7 +46,7 @@ func TestLogDirectiveSyntax(t *testing.T) {
46
}
47
}
48
`,
50
- output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"encoder":{"fields":{"common_log":{"filter":"delete"},"request\u003eremote_addr":{"filter":"ip_mask","ipv4_cidr":24,"ipv6_cidr":32}},"format":"filter","wrap":{"format":"console"}},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
49
+ output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"encoder":{"fields":{"request\u003eremote_addr":{"filter":"ip_mask","ipv4_cidr":24,"ipv6_cidr":32}},"format":"filter","wrap":{"format":"console"}},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`,
50
expectError: false,
51
},
52
{
caddytest/integration/caddyfile_adapt/global_options_log_custom.txt
-4
@@ -3,7 +3,6 @@
3
format filter {
4
wrap console
5
fields {
6
- common_log delete
6
request>remote_addr ip_mask {
7
ipv4 24
8
ipv6 32
@@ -19,9 +18,6 @@
18
"custom-logger": {
19
"encoder": {
20
"fields": {
22
- "common_log": {
23
- "filter": "delete"
24
- },
21
"request\u003eremote_addr": {
22
"filter": "ip_mask",
23
"ipv4_cidr": 24,
modules/caddyhttp/server.go
-9
@@ -187,7 +187,6 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
187
userID, _ := repl.GetString("http.auth.user.id")
188
189
log("handled request",
190
- zap.String("common_log", repl.ReplaceAll(commonLogFormat, commonLogEmptyValue)),
190
zap.String("user_id", userID),
191
zap.Duration("duration", duration),
192
zap.Int("size", wrec.Size()),
@@ -627,14 +626,6 @@ func cloneURL(from, to *url.URL) {
626
}
627
}
628
630
-const (
631
- // commonLogFormat is the common log format. https://en.wikipedia.org/wiki/Common_Log_Format
632
- commonLogFormat = `{http.request.remote.host} ` + commonLogEmptyValue + ` {http.auth.user.id} [{time.now.common_log}] "{http.request.orig_method} {http.request.orig_uri} {http.request.proto}" {http.response.status} {http.response.size}`
633
-
634
- // commonLogEmptyValue is the common empty log value.
635
- commonLogEmptyValue = "-"
636
-)
637
-
629
// Context keys for HTTP request context values.
630
const (
631
// For referencing the server instance
modules/logging/encoders.go
-85
@@ -15,9 +15,6 @@
15
package logging
16
17
import (
18
- "encoding/json"
19
- "fmt"
20
- "strings"
18
"time"
19
20
"github.com/caddyserver/caddy/v2"
@@ -30,7 +27,6 @@ import (
27
func init() {
28
caddy.RegisterModule(ConsoleEncoder{})
29
caddy.RegisterModule(JSONEncoder{})
33
- caddy.RegisterModule(SingleFieldEncoder{})
30
}
31
32
// ConsoleEncoder encodes log entries that are mostly human-readable.
@@ -115,85 +111,6 @@ func (je *JSONEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
111
return nil
112
}
113
118
-// SingleFieldEncoder writes a log entry that consists entirely
119
-// of a single string field in the log entry. This is useful
120
-// for custom, self-encoded log entries that consist of a
121
-// single field in the structured log entry.
122
-type SingleFieldEncoder struct {
123
- zapcore.Encoder `json:"-"`
124
- FieldName string `json:"field,omitempty"`
125
- FallbackRaw json.RawMessage `json:"fallback,omitempty" caddy:"namespace=caddy.logging.encoders inline_key=format"`
126
-}
127
-
128
-// CaddyModule returns the Caddy module information.
129
-func (SingleFieldEncoder) CaddyModule() caddy.ModuleInfo {
130
- return caddy.ModuleInfo{
131
- ID: "caddy.logging.encoders.single_field",
132
- New: func() caddy.Module { return new(SingleFieldEncoder) },
133
- }
134
-}
135
-
136
-// Provision sets up the encoder.
137
-func (se *SingleFieldEncoder) Provision(ctx caddy.Context) error {
138
- caddy.Log().Named("caddy.logging.encoders.single_field").Warn("the 'single_field' encoder is deprecated and will be removed soon!")
139
- if se.FallbackRaw != nil {
140
- val, err := ctx.LoadModule(se, "FallbackRaw")
141
- if err != nil {
142
- return fmt.Errorf("loading fallback encoder module: %v", err)
143
- }
144
- se.Encoder = val.(zapcore.Encoder)
145
- }
146
- if se.Encoder == nil {
147
- se.Encoder = nopEncoder{}
148
- }
149
- return nil
150
-}
151
-
152
-// Clone wraps the underlying encoder's Clone. This is
153
-// necessary because we implement our own EncodeEntry,
154
-// and if we simply let the embedded encoder's Clone
155
-// be promoted, it would return a clone of that, and
156
-// we'd lose our SingleFieldEncoder's EncodeEntry.
157
-func (se SingleFieldEncoder) Clone() zapcore.Encoder {
158
- return SingleFieldEncoder{
159
- Encoder: se.Encoder.Clone(),
160
- FieldName: se.FieldName,
161
- }
162
-}
163
-
164
-// EncodeEntry partially implements the zapcore.Encoder interface.
165
-func (se SingleFieldEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) {
166
- for _, f := range fields {
167
- if f.Key == se.FieldName {
168
- buf := bufferpool.Get()
169
- buf.AppendString(f.String)
170
- if !strings.HasSuffix(f.String, "\n") {
171
- buf.AppendByte('\n')
172
- }
173
- return buf, nil
174
- }
175
- }
176
- if se.Encoder == nil {
177
- return nil, fmt.Errorf("no fallback encoder defined")
178
- }
179
- return se.Encoder.EncodeEntry(ent, fields)
180
-}
181
-
182
-// UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
183
-//
184
-// single_field <field_name>
185
-//
186
-func (se *SingleFieldEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
187
- for d.Next() {
188
- var fieldName string
189
- if !d.AllArgs(&fieldName) {
190
- return d.ArgErr()
191
- }
192
- se.FieldName = d.Val()
193
- }
194
- return nil
195
-}
196
-
114
// LogEncoderConfig holds configuration common to most encoders.
115
type LogEncoderConfig struct {
116
MessageKey *string `json:"message_key,omitempty"`
@@ -350,9 +267,7 @@ var bufferpool = buffer.NewPool()
267
var (
268
_ zapcore.Encoder = (*ConsoleEncoder)(nil)
269
_ zapcore.Encoder = (*JSONEncoder)(nil)
353
- _ zapcore.Encoder = (*SingleFieldEncoder)(nil)
270
271
_ caddyfile.Unmarshaler = (*ConsoleEncoder)(nil)
272
_ caddyfile.Unmarshaler = (*JSONEncoder)(nil)
357
- _ caddyfile.Unmarshaler = (*SingleFieldEncoder)(nil)
273
)