From c441bdf2d026e890df21ae3aa89c8e6a638df3c5 Mon Sep 17 00:00:00 2001 From: iRedMail <2048991+iredmail@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:36:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20middleware/logger/:=20log=20clie?= =?UTF-8?q?nt=20IP=20address=20by=20default=20(#2755)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * middleware/logger: Log client IP address by default. * Update doc. --- docs/api/middleware/logger.md | 4 ++-- middleware/logger/config.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/middleware/logger.md b/docs/api/middleware/logger.md index a01e9bd5..97c3c738 100644 --- a/docs/api/middleware/logger.md +++ b/docs/api/middleware/logger.md @@ -97,7 +97,7 @@ app.Use(logger.New(logger.Config{ | Next | `func(*fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` | | Done | `func(*fiber.Ctx, []byte)` | 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. | `nil` | | CustomTags | `map[string]LogFunc` | tagFunctions defines the custom tag action. | `map[string]LogFunc` | -| Format | `string` | Format defines the logging tags. | `[${time}] ${status} - ${latency} ${method} ${path}\n` | +| Format | `string` | Format defines the logging tags. | `[${time}] ${ip} ${status} - ${latency} ${method} ${path}\n` | | TimeFormat | `string` | TimeFormat defines the time format for log timestamps. | `15:04:05` | | TimeZone | `string` | TimeZone can be specified, such as "UTC" and "America/New_York" and "Asia/Chongqing", etc | `"Local"` | | TimeInterval | `time.Duration` | TimeInterval is the delay before the timestamp is updated. | `500 * time.Millisecond` | @@ -112,7 +112,7 @@ app.Use(logger.New(logger.Config{ var ConfigDefault = Config{ Next: nil, Done: nil, - Format: "[${time}] ${status} - ${latency} ${method} ${path}\n", + Format: "[${time}] ${ip} ${status} - ${latency} ${method} ${path}\n", TimeFormat: "15:04:05", TimeZone: "Local", TimeInterval: 500 * time.Millisecond, diff --git a/middleware/logger/config.go b/middleware/logger/config.go index 5b91a065..10b382b9 100644 --- a/middleware/logger/config.go +++ b/middleware/logger/config.go @@ -28,7 +28,7 @@ type Config struct { // Format defines the logging tags // - // Optional. Default: [${time}] ${status} - ${latency} ${method} ${path}\n + // Optional. Default: [${time}] ${ip} ${status} - ${latency} ${method} ${path}\n Format string // TimeFormat https://programming.guide/go/format-parse-string-time-date-example.html @@ -86,7 +86,7 @@ type LogFunc func(output Buffer, c *fiber.Ctx, data *Data, extraParam string) (i var ConfigDefault = Config{ Next: nil, Done: nil, - Format: "[${time}] ${status} - ${latency} ${method} ${path}\n", + Format: "[${time}] ${ip} ${status} - ${latency} ${method} ${path}\n", TimeFormat: "15:04:05", TimeZone: "Local", TimeInterval: 500 * time.Millisecond,