shreemaan-abhishek opened a new pull request, #13568:
URL: https://github.com/apache/apisix/pull/13568
### Description
Setting `log_format` on a logger plugin (via `plugin_metadata` or plugin
`conf`) **replaces** the default rich log entry with a flat custom format. The
custom format only substitutes scalar `$variables`, so it silently drops every
default field that has no scalar-variable equivalent: the full request/response
header maps, the parsed querystring, the composed request URL, the APISIX
version, and the computed `apisix_latency`.
Customers often set `log_format` just to add or rename one field, and
unknowingly lose all of those.
This PR adds **`log_format_extra`**: an additive log format that keeps the
default rich log entry intact and only overlays the user-defined fields on top.
It is ignored when `log_format` is set (which keeps the replace semantics).
It also exposes a new core variable **`upstream_unresolved_host`** — the
upstream host *before* DNS resolution (the configured domain or IP of the
picked node). The default log only carries `upstream` (`$upstream_addr`, the
resolved `ip:port`), so this variable lets users log the original hostname via
`log_format_extra`.
### Example
```json
"plugin_metadata": {
"log_format_extra": {
"upstream_host": "$upstream_unresolved_host"
}
}
```
The log keeps every default field (`request`, `response`, `server`,
`route_id`, ...) and gains `upstream_host`.
### Changes
- `apisix/utils/log-util.lua`: `get_log_entry` builds the default log then
overlays `log_format_extra` (http subsystem only, since the default log is
http-only).
- `apisix/core/ctx.lua`: register the `upstream_unresolved_host` variable.
- `apisix/balancer.lua`: stash the pre-DNS host on `ctx` when picking a
server (single-node and balancer paths).
- `apisix/plugins/loki-logger.lua`, `apisix/plugins/file-logger.lua`: accept
`log_format_extra` in conf and metadata schemas.
- Docs: `loki-logger.md`, `apisix-variable.md`.
- Tests: enrich scenario in `t/plugin/file-logger.t` (self-contained) and
`t/plugin/loki-logger.t`.
### Checklist
- [x] Tests added
- [x] Docs updated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]