You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some Fiber middleware registers logger middleware tags automatically. Register the producing middleware before `logger.New()` and then use the tag in `Format`.
The logger middleware resolves tags in this order:
129
+
130
+
1. Built-in logger tags, such as `${method}`, `${path}`, and `${status}`.
131
+
2. Globally registered tags from Fiber middleware or `logger.RegisterTag`.
132
+
3.`Config.CustomTags`, which override tags with the same name for that logger instance.
133
+
134
+
The following tags are registered by Fiber middleware when the middleware is initialized:
135
+
136
+
| Tag | Registered by | Value |
137
+
| :-- | :------------ | :---- |
138
+
|`${requestid}`|`requestid.New()`| Request ID stored by the requestid middleware. |
139
+
|`${username}`|`basicauth.New()`| Authenticated username stored by the basicauth middleware. |
140
+
|`${api-key}`|`keyauth.New()`| Redacted API key stored by the keyauth middleware. |
141
+
|`${csrf-token}`|`csrf.New()`| Redacted marker when the csrf middleware stores a token. |
142
+
|`${session-id}`|`session.New()` or `session.NewWithStore()`| Redacted session ID stored by the session middleware. |
143
+
144
+
:::note
145
+
Auto-registered tags are access-log tags for `middleware/logger`. Application logs from the `log` package use their own context tag registry.
146
+
:::
147
+
148
+
### Register Tags from Custom Middleware
149
+
150
+
Third-party middleware can expose logger tags with `logger.RegisterTag` or `logger.MustRegisterTag`. Use `sync.Once` so the tag is registered once even when the middleware is initialized multiple times.
To combine the logger middleware with loggers like Zerolog, Zap, or Logrus, use the `LoggerToWriter` helper to adapt them to an `io.Writer`.
@@ -167,7 +247,7 @@ Writing to `os.File` is goroutine-safe, but custom streams may require locking t
167
247
| Next |`func(fiber.Ctx) bool`| Next defines a function to skip this middleware when it returns true. |`nil`|
168
248
| Skip |`func(fiber.Ctx) bool`| Skip is a function to determine if logging is skipped or written to Stream. |`nil`|
169
249
| Done |`func(fiber.Ctx, []byte)`| Done is a function that is called after the log string for a request is written to Stream, and pass the log string as parameter. |`nil`|
170
-
| CustomTags |`map[string]LogFunc`|tagFunctions defines the custom tag action. |`map[string]LogFunc`|
250
+
| CustomTags |`map[string]LogFunc`|Defines custom tag actions for this logger instance. These tags override built-in and globally registered tags with the same name.|`map[string]LogFunc`|
171
251
|`Format`|`string`| Defines the logging tags. See more in [Predefined Formats](#predefined-formats), or create your own using [Tags](#constants). |`[${time}] ${ip} ${status} - ${latency} ${method} ${path} ${error}\n` (same as `DefaultFormat`) |
172
252
| TimeFormat |`string`| TimeFormat defines the time format for log timestamps. |`15:04:05`|
173
253
| TimeZone |`string`| TimeZone can be specified, such as "UTC" and "America/New_York" and "Asia/Chongqing", etc |`"Local"`|
0 commit comments