Skip to content

Commit fca8e4d

Browse files
ptsteadmanaldas
authored andcommitted
Update logger middleware docs to show CustomTimeFormat
1 parent 67469b4 commit fca8e4d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

website/content/middleware/logger.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ method=GET, uri=/, status=200
3939
## Configuration
4040

4141
```go
42+
// LoggerConfig defines the config for Logger middleware.
4243
LoggerConfig struct {
4344
// Skipper defines a function to skip middleware.
4445
Skipper Skipper
@@ -49,12 +50,14 @@ LoggerConfig struct {
4950
// - time_unix_nano
5051
// - time_rfc3339
5152
// - time_rfc3339_nano
53+
// - time_custom
5254
// - id (Request ID)
5355
// - remote_ip
5456
// - uri
5557
// - host
5658
// - method
5759
// - path
60+
// - protocol
5861
// - referer
5962
// - user_agent
6063
// - status
@@ -66,14 +69,16 @@ LoggerConfig struct {
6669
// - header:<NAME>
6770
// - query:<NAME>
6871
// - form:<NAME>
69-
// - cookie:<NAME>
7072
//
7173
// Example "${remote_ip} ${status}"
7274
//
7375
// Optional. Default value DefaultLoggerConfig.Format.
74-
Format string `json:"format"`
76+
Format string `yaml:"format"`
7577

76-
// Output is a writer where logs are written.
78+
// Optional. Default value DefaultLoggerConfig.CustomTimeFormat.
79+
CustomTimeFormat string `yaml:"custom_time_format"`
80+
81+
// Output is a writer where logs in JSON format are written.
7782
// Optional. Default value os.Stdout.
7883
Output io.Writer
7984
}
@@ -84,10 +89,10 @@ LoggerConfig struct {
8489
```go
8590
DefaultLoggerConfig = LoggerConfig{
8691
Skipper: DefaultSkipper,
87-
Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}","host":"${host}",` +
88-
`"method":"${method}","uri":"${uri}","status":${status},"error":"${error}","latency":${latency},` +
89-
`"latency_human":"${latency_human}","bytes_in":${bytes_in},` +
90-
`"bytes_out":${bytes_out}}` + "\n",
91-
Output: os.Stdout
92+
Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}",` +
93+
`"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` +
94+
`"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` +
95+
`,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n",
96+
CustomTimeFormat: "2006-01-02 15:04:05.00000",
9297
}
9398
```

0 commit comments

Comments
 (0)