mirror of https://github.com/gofiber/fiber.git
commit
ea50823730
|
@ -13,8 +13,8 @@ Logger middleware for [Fiber](https://github.com/gofiber/fiber) that logs HTTP r
|
|||
func New(config ...Config) fiber.Handler
|
||||
```
|
||||
|
||||
### Examples
|
||||
Import the middleware package that is part of the Fiber web framework
|
||||
## Examples
|
||||
First ensure the appropriate packages are imported
|
||||
```go
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
@ -22,17 +22,42 @@ import (
|
|||
)
|
||||
```
|
||||
|
||||
After you initiate your Fiber app, you can use the following possibilities:
|
||||
#### **Initialization / Default Config**
|
||||
```go
|
||||
// Default middleware config
|
||||
app.Use(logger.New())
|
||||
```
|
||||
|
||||
// Or extend your config for customization
|
||||
#### **Logging Request ID**
|
||||
```go
|
||||
app.Use(requestid.New())
|
||||
|
||||
app.Use(logger.New(logger.Config{
|
||||
// For more options, see the Config section
|
||||
Format: "${pid} ${locals:requestid} ${status} - ${method} ${path}\n",
|
||||
}))
|
||||
```
|
||||
|
||||
#### **Changing TimeZone & TimeFormat**
|
||||
|
||||
```go
|
||||
app.Use(logger.New(logger.Config{
|
||||
Format: "${pid} ${status} - ${method} ${path}\n",
|
||||
TimeFormat: "02-Jan-2006",
|
||||
TimeZone: "America/New_York",
|
||||
Output: os.Stdout,
|
||||
}))
|
||||
```
|
||||
|
||||
#### **Custom File Writer**
|
||||
```go
|
||||
file, err := os.OpenFile("./123.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
app.Use(logger.New(logger.Config{
|
||||
Output: file,
|
||||
}))
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue