Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Update middleware/logger docs #2224

Merged
merged 2 commits into from Nov 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 36 additions & 11 deletions middleware/logger/README.md
Expand Up @@ -87,6 +87,20 @@ app.Use(logger.New(logger.Config{
}))
```

### Callback after log is written

```go
app.Use(logger.New(logger.Config{
TimeFormat: time.RFC3339Nano,
TimeZone: "Asia/Shanghai",
Done: func(c *fiber.Ctx, logString []byte) {
if c.Response().StatusCode() != fiber.StatusOK {
reporter.SendToSlack(logString)
}
},
}))
```

## Config
```go
// Config defines the config for middleware.
Expand All @@ -96,16 +110,22 @@ type Config struct {
// Optional. Default: nil
Next func(c *fiber.Ctx) bool

// CustomTags defines the custom tag action
// Done is a function that is called after the log string for a request is written to Output,
// and pass the log string as parameter.
//
// Optional. Default: map[string]LogFunc{}
// Optional. Default: nil
Done func(c *fiber.Ctx, logString []byte)

// tagFunctions defines the custom tag action
//
// Optional. Default: map[string]LogFunc
CustomTags map[string]LogFunc
panjf2000 marked this conversation as resolved.
Show resolved Hide resolved

// Format defines the logging tags
//
// Optional. Default: [${time}] ${status} - ${latency} ${method} ${path}\n
Format string

// TimeFormat https://programming.guide/go/format-parse-string-time-date-example.html
//
// Optional. Default: 15:04:05
Expand All @@ -123,20 +143,25 @@ type Config struct {

// Output is a writer where logs are written
//
// Default: os.Stderr
// Default: os.Stdout
Output io.Writer

enableColors bool
enableLatency bool
timeZoneLocation *time.Location
}
```

## Default Config
```go
var ConfigDefault = Config{
Next: nil,
Format: "[${time}] ${status} - ${latency} ${method} ${path}\n",
TimeFormat: "15:04:05",
TimeZone: "Local",
TimeInterval: 500 * time.Millisecond,
Output: os.Stderr,
Next: nil,
Done: nil,
Format: "[${time}] ${status} - ${latency} ${method} ${path}\n",
TimeFormat: "15:04:05",
TimeZone: "Local",
TimeInterval: 500 * time.Millisecond,
Output: os.Stderr,
ReneWerner87 marked this conversation as resolved.
Show resolved Hide resolved
}
```

Expand Down